×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    44

    Is this no longer exist?

    I am using Qt 4.6.2 and I am reading the book "C++ GUI Programming with Qt 4" the first Edition.
    In the book, they said that
    In the constructor, we call setupUi() to initialize the form. Thanks to multiple inheritance, we can access Ui::GoToCellDialog's members directly. After creating the user interface, setupUi() will also automatically connect any slots that follow the naming convention on_objectName_signalName() to the corresponding objectName's signalName() signal. In our example, this means that setupUi() will establish the following signalslot connection:

    connect(lineEdit, SIGNAL(textChanged(const QString &)),
    this, SLOT(on_lineEdit_textChanged()));




    However, it didn't work unless I wrote the connect manually. Is that changed?

    my header file
    PHP Code:
    #ifndef GOTOCELLDIALOG_H
    #define GOTOCELLDIALOG_H
    #include <QDialog>
    #include "ui_gotocelldialog.h"
    class GoToCellDialog : public QDialog, public Ui::GoToCellDialog
    {
        
    Q_OBJECT
    public:
                
    GoToCellDialog(QWidget *parent 0);
    private 
    slots:
        
    void on_lineEdit_textChange();
    };
    #endif // GOTOCELLDIALOG_H 
    my cpp file
    PHP Code:
    #include <QtGui>
    #include "gotocelldialog.h"
    GoToCellDialog::GoToCellDialog(QWidget *parent)
        : 
    QDialog(parent)
    {
        
    setupUi(this);
        
    QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
        
    lineEdit->setValidator(new QRegExpValidator(regExpthis));
        
    connect(okButtonSIGNAL(clicked()), thisSLOT(accept()));
        
    connect(cancelButtonSIGNAL(clicked()), thisSLOT(reject()));
    //unless I wrote the following connect manually, the okButton would be never enabled.
        
    connect(lineEditSIGNAL(textChanged(QString)), thisSLOT(on_lineEdit_textChange()));
    }
    void GoToCellDialog::on_lineEdit_textChange()
    {
        
    okButton->setEnabled(lineEdit->hasAcceptableInput());

    and the main file:

    PHP Code:
    #include <QApplication>
    //#include <QDialog>
    //#include <ui_gotocelldialog.h>
    #include "gotocelldialog.h"
    int main(int argcchar *argv[])
    {
        
    QApplication app(argcargv);
        
    //Ui::GoToCellDialog ui;
        //QDialog *dialog = new QDialog;
        //ui.setupUi(dialog);
        //dialog->show();
        
    GoToCellDialog *dialog = new GoToCellDialog;
        
    dialog->show();
        return 
    app.exec();

    Anyone help is appreciated.

  2. #2
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Is this no longer exist?

    You have a typo in slot's name.

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    44

    Re: Is this no longer exist?

    problem solved. It should be void on_lineEdit_textChanged(). I forgot the d. And since textChange was not a signal of lineEdit, the on_lineEdit_textchange became a normal slot. =.=

    Thanks for all replies.

  4. #4
    Nokia Developer Champion
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Is this no longer exist?

    I find it's worthwhile to capture the return code from connect and test it with a Q_ASSERT, to catch misspellings and name changes that break connections.

    (Note: Don't do "Q_ASSERT(connect(...));", since the connect will not be executed in final code where asserts are disabled. Rather do "bool ok = connect(...); Q_ASSERT(ok);".)

  5. #5
    Nokia Developer Champion
    Join Date
    Mar 2009
    Posts
    430

    Re: Is this no longer exist?

    Quote Originally Posted by danhicksbyron View Post
    I find it's worthwhile to capture the return code from connect and test it with a Q_ASSERT, to catch misspellings and name changes that break connections.)
    Do you have a pattern for this? I like your idea but I usually have around 10 connect statements in a single function and I dont want to have 10 bools just for checking the connects. Do you reuse your ok variable in this case or is there another solution?

  6. #6
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Is this no longer exist?

    The test code:
    Code:
    #include <QApplication>
    #include <QDebug>
    
    #include "widget.h"
    
    int
    main (int argc, char **argv)
    {
        QApplication app(argc, argv);
        Widget w;
    
        w.show();
    
        return app.exec();
    }
    Code:
    #ifndef WIDGET_H
    #define WIDGET_H
    
    #include <QLineEdit>
    
    class Widget : public QWidget
    {
        Q_OBJECT
    
    public:
        Widget(QWidget *parent=0);
    
    public slots:
        void on_lineEdit_textChange();
    
    private:
        QLineEdit *lineEdit;
    };
    
    #endif //WIDGET_H
    Code:
    #include <QDebug>
    
    #include "widget.h"
    
    Widget::Widget(QWidget *parent)
        : QWidget(parent)
    {
        lineEdit = new QLineEdit(this);
        QMetaObject::connectSlotsByName(this);
    }
    
    void Widget::on_lineEdit_textChange()
    {
        qDebug() << __PRETTY_FUNCTION__;
    }
    What happens when I run the test application:
    Code:
    $ ./signals 
    QMetaObject::connectSlotsByName: No matching signal for on_lineEdit_textChange()
    Last edited by divanov; 2010-03-15 at 12:27.

  7. #7
    Nokia Developer Champion
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Is this no longer exist?

    Quote Originally Posted by axeljaeger View Post
    Do you have a pattern for this? I like your idea but I usually have around 10 connect statements in a single function and I dont want to have 10 bools just for checking the connects. Do you reuse your ok variable in this case or is there another solution?
    Well, you can do:
    Code:
    bool ok;
    ok = connect(...);
    Q_ASSERT(ok);
    ok = connect(...);
    Q_ASSERT(ok);
    ...
    Probably a dozen other options. Among which is to create an assertConnect method:

    Code:
    void MyClass::assertConnect(bool ok) {
    Q_ASSERT(ok);
    }
    
    then code:
    
    assertConnect(connect(...));
    ...

  8. #8
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Is this no longer exist?

    Quote Originally Posted by danhicksbyron View Post
    Well, you can do...
    Do you dislike simple ways?

  9. #9
    Nokia Developer Champion
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Is this no longer exist?

    The guy asked for options and I gave him some. What's your problem with that???

  10. #10
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Is this no longer exist?

    Quote Originally Posted by danhicksbyron View Post
    The guy asked for options and I gave him some. What's your problem with that???
    Other people may learn from your words.

Similar Threads

  1. BLDMAKE ERROR: Directory does not exist
    By Mathematix08 in forum Symbian Tools & SDKs
    Replies: 17
    Last Post: 2009-11-05, 09:34
  2. Big Issues and no reply from Ovi Support: Item no longer available on Ovi Store
    By BlackTomcat in forum [Closed] Publishing to Nokia Store
    Replies: 4
    Last Post: 2009-06-20, 14:19
  3. Replies: 3
    Last Post: 2007-07-26, 09:11
  4. MMS Java library no longer available, alternatives?
    By DarkCK05 in forum General Messaging
    Replies: 4
    Last Post: 2006-01-24, 12:03
  5. The requested protocol does not exist http://www.yahoo.com
    By polrtex in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2004-04-25, 06:51

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •