Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. The Lounge
  4. Incompatibility between the IDE and the book I read to learn Qt5
Forum Updated to NodeBB v4.3 + New Features

Incompatibility between the IDE and the book I read to learn Qt5

Scheduled Pinned Locked Moved Unsolved The Lounge
18 Posts 7 Posters 5.8k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • tomyT Offline
    tomyT Offline
    tomy
    wrote on last edited by tomy
    #4

    As far as I could, I figured out the changes and wrote the followings.
    First I designed this form. Then wrote the following codes:

    The gotocell.h file:

    #ifndef GOTOCELL_H
    #define GOTOCELL_H
    
    #include <QDialog>
    class QLineEdit;
    class QLabel;
    class QPushButton;
    class QSpaceItem;
    namespace Ui {
    class GoToCell;
    }
    
    class GoToCell : public QDialog
    {
        Q_OBJECT
    
    public:
        explicit GoToCell(QWidget *parent = 0);
        ~GoToCell();
    private slots:
        void on_LineEdit_TextChanged();
    private:
        Ui::GoToCell *ui;
     QPushButton* okButton;
     QPushButton* cancelButton;
     QSpaceItem* spacerItem;
     QLineEdit* lineEdit;
     QLabel* label;
    };
    
    #endif // GOTOCELL_H
    
    

    The gotocell.cpp file:

    #include "gotocell.h"
    #include "ui_gotocell.h"
    #include <QtWidgets>
    
    GoToCell::GoToCell(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::GoToCell)
    {
        ui->setupUi(this);
    
        QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
        lineEdit -> setValidator(new QRegExpValidator(regExp, this));
    
        connect(lineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(on_LineEdit_TextChanged()));
        connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
        connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
    }
    
    //---------------------------------
    
    void GoToCell::on_LineEdit_TextChanged(){
        okButton ->setEnabled(lineEdit->hasAcceptableInput());
    }
    
    //---------------------------
    
    GoToCell::~GoToCell()
    {
        delete ui;
    }
    
    

    And the main.cpp file:

    #include "gotocell.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
        GoToCell* gtc = new GoToCell;
        gtc -> show();
    
        return app.exec();
    }
    
    

    After running, the program crashes and shows the message below:
    QMetaObject::connectSlotsByName: No matching signal for on_LineEdit_TextChanged()

    Any idea on my main problem on this thread or about this error please?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #5

      Hi,

      lineEdit is not initialized nor is okButton and on_LineEdit_TextChanged uses the format for automatic connection used by the widgets built with designer. The error message means that your Designer based UI doesn't contain any QLineEdit matching the name LineEdit.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      tomyT 1 Reply Last reply
      1
      • E Offline
        E Offline
        eureka
        wrote on last edited by
        #6

        I've been working through this tutorial .. I note that you have misnamed "cancelButton" to "cancleButton" in Qt Creator screenshot.

        1 Reply Last reply
        0
        • Ni.SumiN Offline
          Ni.SumiN Offline
          Ni.Sumi
          wrote on last edited by Ni.Sumi
          #7

          Hi @tomy
          Rename your slot (//on_LineEdit_TextChanged()//), it works.

          This is because, when you create setupUI() function, which was created at the time of Dialog/window using QtDesinger. And it does the search function/slot basing on name like "on_widgetName_eventNaeme()" . But if you make some own slot/function similar like this starting with" on_" prefix like what you did in your case "on_LineEdit_TextChanged()" ,which is not related directly to widgetname with valid event name, connect() fails.

          So when you make own connection or slot, you shouldn't USE the "on_" prefix for the slot's name (to avoid confusion)because connectSlotsByName is also called at the end of setupUi which would again throw the warning/error that there is nNo matching signal for on_LineEdit_TextChanged()/slot.

          1 Reply Last reply
          1
          • SGaistS SGaist

            Hi,

            lineEdit is not initialized nor is okButton and on_LineEdit_TextChanged uses the format for automatic connection used by the widgets built with designer. The error message means that your Designer based UI doesn't contain any QLineEdit matching the name LineEdit.

            tomyT Offline
            tomyT Offline
            tomy
            wrote on last edited by
            #8

            Hi SGaist, thanks for your explanation.

            lineEdit is not initialized nor is okButton

            But I used them and even changed their properties in the design mode!

            and on_LineEdit_TextChanged uses the format for automatic connection used by the widgets built with designer.

            I don't exactly know what "the format for automatic connection" means but I think you meant, since I haven't initialize, say, the lineEdit (this way:lineEdit = new QLineEdit;), so the program uses the one I made with the designer. If so, OK, this is what I want. That is, I want the works I have done on the designer mode to be used not useless.

            The error message means that your Designer based UI doesn't contain any QLineEdit matching the name LineEdit.

            Why should it match the name LineEdit please?
            I haven't used the name LineEdit in my codes. I've used lineEdit which exists in designer form. If you meant that I have used LineEdit in theon_LineEdit_TextChanged()function/slot, according to my experience on C++, the names of the user defined functions has nothing to do with the works they do.

            PS: I even changed the name of that slot to on_lineEdit_TextChanged(). The same result.

            @eureka said:

            I've been working through this tutorial .. I note that you have misnamed "cancelButton" to "cancleButton" in Qt Creator screenshot.

            I corrected it, thanks. :-)

            @Ni.Sumi said:

            Hi @tomy
            Rename your slot (//on_LineEdit_TextChanged()//), it works.

            Thank you for your explanations. I tried to understand them.
            Please read my comment on the name of functions/slots above. And that, I even changed the name of that slot.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #9

              So lineEdit belongs to the UI created with Designer, you should access it using ui->lineEdit. What you are currently using is a raw pointer pointing to nothing.

              The automatic connection and function naming scheme has nothing to do with core C++ principles. You should take a look at the Designer manual. Things like automatic connection and how it works is explained there (what @Ni-Sumi already wrote with a bit more practical examples)

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              tomyT 1 Reply Last reply
              1
              • J Offline
                J Offline
                JordanHarris
                wrote on last edited by
                #10

                There are some great guides on what's new in Qt5 and how to transition to Qt5. I suggest finding those and reading them over. There's really not too much you need to know. The most important thing to do first IMO is to learn the newer Signal and Slot syntax. I find it to be much more powerful than the old way, plus it's much more efficient. You should make a habit of replacing the old Signal and Slot code with the new style. Here is a guide for transitioning from Qt4 to Qt5. You should get the hang of it after a while. I managed to do so using the resources available to me. It's not ideal to learn an older framework and adapt it to the newer one, but that's just what you'll have to do for now. Luckily, there's all kinds of resources (like examples and tutorials) all over the Web using Qt5, so it's not too hard to pick it up. Good luck on your Qt journey. I've only been using it for a few months and I've grown to like it more than any other framework. It starts to grow on you and things just start making sense. It's so consistent that you'll be using classes without ever reading the documentation.

                kshegunovK 1 Reply Last reply
                0
                • SGaistS SGaist

                  So lineEdit belongs to the UI created with Designer, you should access it using ui->lineEdit. What you are currently using is a raw pointer pointing to nothing.

                  The automatic connection and function naming scheme has nothing to do with core C++ principles. You should take a look at the Designer manual. Things like automatic connection and how it works is explained there (what @Ni-Sumi already wrote with a bit more practical examples)

                  tomyT Offline
                  tomyT Offline
                  tomy
                  wrote on last edited by tomy
                  #11

                  @SGaist said:

                  So lineEdit belongs to the UI created with Designer, you should access it using ui->lineEdit. What you are currently using is a raw pointer pointing to nothing.

                  The automatic connection and function naming scheme has nothing to do with core C++ principles. You should take a look at the Designer manual. Things like automatic connection and how it works is explained there (what @Ni-Sumi already wrote with a bit more practical examples)

                  I found this in Designer manual which seems to be fine and useful (especially for a beginner), but, and just as usual, there are imperfect parts in it!
                  I was precisely reading the explanations until arrived at the Calculator Form point. But neither there nor in Calculator Form's page, the explanations are complete!

                  For example, please look at the that Calculator Form's page:

                  • It doesn't specify what type of the forms I need to create using the Qt creator!
                    (I guess I should create one from File -> New File or Project -> Qt -> Qt Designer Form -> Widget)

                  • In the next part, it says:
                    "To ensure that the example can use this file, we need to include a FORMS declaration in the example's project file:
                    FORMS = calculatorform.ui"

                  I think it means that I should type the above statement inside a project file (here, the calculatorform .pro). But creating a form using the way I mentioned just create a .ui file, "form.ui", and not any other file (for example, a .pro file)!

                  Seemingly, if I can create such a .pro file and put that statement into it, I should do some action (building it using the Build button), so that the program will produce a header file, then, for proceeding the track.

                  1 Reply Last reply
                  0
                  • J JordanHarris

                    There are some great guides on what's new in Qt5 and how to transition to Qt5. I suggest finding those and reading them over. There's really not too much you need to know. The most important thing to do first IMO is to learn the newer Signal and Slot syntax. I find it to be much more powerful than the old way, plus it's much more efficient. You should make a habit of replacing the old Signal and Slot code with the new style. Here is a guide for transitioning from Qt4 to Qt5. You should get the hang of it after a while. I managed to do so using the resources available to me. It's not ideal to learn an older framework and adapt it to the newer one, but that's just what you'll have to do for now. Luckily, there's all kinds of resources (like examples and tutorials) all over the Web using Qt5, so it's not too hard to pick it up. Good luck on your Qt journey. I've only been using it for a few months and I've grown to like it more than any other framework. It starts to grow on you and things just start making sense. It's so consistent that you'll be using classes without ever reading the documentation.

                    kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on last edited by kshegunov
                    #12

                    @JordanHarris
                    Hello,

                    The most important thing to do first IMO is to learn the newer Signal and Slot syntax. I find it to be much more powerful than the old way, plus it's much more efficient.

                    Indeed, this:

                    connect(mySpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), mySlider, &QSlider::setValue);
                    

                    instead of this:

                    connect(mySpinBox, SIGNAL(valueChanged(int)), mySlider, SLOT(setValue(int));
                    

                    is really simpler and much more beautiful ...

                    Regarding efficiency, well that point is simply moot. Quite irrelevant, if I may add, unless you can prove that the bottelneck for an application are the signal-slot invocations, which I don't believe you can.

                    Kind regards.

                    Read and abide by the Qt Code of Conduct

                    1 Reply Last reply
                    1
                    • tomyT Offline
                      tomyT Offline
                      tomy
                      wrote on last edited by tomy
                      #13

                      If I can, I state my opinion upon the other subjects later. But what is important for me at this point is to move forward along the Qt's path. Please read my previous post. You all have experienced these cases and are able to cube with them.
                      If possible, please guide me on what are questions for me.

                      kshegunovK 1 Reply Last reply
                      0
                      • tomyT tomy

                        If I can, I state my opinion upon the other subjects later. But what is important for me at this point is to move forward along the Qt's path. Please read my previous post. You all have experienced these cases and are able to cube with them.
                        If possible, please guide me on what are questions for me.

                        kshegunovK Offline
                        kshegunovK Offline
                        kshegunov
                        Moderators
                        wrote on last edited by kshegunov
                        #14

                        @tomy
                        Right, sorry for the sarcasm put and the somewhat off-topic-ish comment, as it doesn't really relate to your question. I don't really auto-connect my signals and slots and I believe it to be a terrible idea in the first place. This tutorial seems somewhat useful. Taking it from the top:

                        1. The .pro file is the definition of your project encapsulating the names of the source files to be compiled, the headers, the resources, forms, linker flags and compiler flags and other Qt (and non-Qt) related stuff. The file is needed by qmake, which will read the file and retranslate it into a makefile that the compiler can use to build your project.
                        2. The .ui file is an XML file that is created by the designer (integrated into QtCreator) and which contains the definitions of your forms. When qmake is preparing your project for building, it will run uic (the user interface compiler) to read the form and create a form header that you can include in your source to access the form.

                        Suppose you have a form that is for a widget (it's pretty much the same for a dialog or a main window).
                        Designer view

                        The user interface compiler will create the file "ui_moduletoolboxpage.h" from the "moduletoolboxpage.ui" file. This header contains:

                        /********************************************************************************
                        ** Form generated from reading UI file 'moduletoolboxpage.ui'
                        **
                        ** Created by: Qt User Interface Compiler version 5.3.0
                        **
                        ** WARNING! All changes made in this file will be lost when recompiling UI file!
                        ********************************************************************************/
                        
                        #ifndef UI_MODULETOOLBOXPAGE_H
                        #define UI_MODULETOOLBOXPAGE_H
                        
                        #include <QtCore/QVariant>
                        #include <QtWidgets/QAction>
                        #include <QtWidgets/QApplication>
                        #include <QtWidgets/QButtonGroup>
                        #include <QtWidgets/QHeaderView>
                        #include <QtWidgets/QVBoxLayout>
                        #include <QtWidgets/QWidget>
                        
                        QT_BEGIN_NAMESPACE
                        
                        class Ui_ModuleToolboxPage
                        {
                        public:
                            QVBoxLayout *verticalLayout;
                        
                            void setupUi(QWidget *ModuleToolboxPage)
                            {
                                if (ModuleToolboxPage->objectName().isEmpty())
                                    ModuleToolboxPage->setObjectName(QStringLiteral("ModuleToolboxPage"));
                                ModuleToolboxPage->resize(719, 384);
                                verticalLayout = new QVBoxLayout(ModuleToolboxPage);
                                verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
                        
                                retranslateUi(ModuleToolboxPage);
                        
                                QMetaObject::connectSlotsByName(ModuleToolboxPage);
                            } // setupUi
                        
                            void retranslateUi(QWidget *ModuleToolboxPage)
                            {
                                ModuleToolboxPage->setWindowTitle(QApplication::translate("ModuleToolboxPage", "Form", 0));
                            } // retranslateUi
                        
                        };
                        
                        namespace Ui {
                            class ModuleToolboxPage: public Ui_ModuleToolboxPage {};
                        } // namespace Ui
                        
                        QT_END_NAMESPACE
                        
                        #endif // UI_MODULETOOLBOXPAGE_H
                        

                        The class name comes from the object name: class Ui_ModuleToolboxPage is named after the root object, which in my case (see the picture) is named ModuleToolboxPage. And this line:

                        QMetaObject::connectSlotsByName(ModuleToolboxPage);
                        

                        connects slots automatically depending on the slot's name.

                        To use that form, you include this generated header (remember, it's generated automatically from qmake/uic when the form file is registered in the project file like this: FORM += moduletoolboxpage.ui, and this is done automatically as well when you create it in QtCreator). So suppose I have a dialog I want to initialize with this form, I'd do something like this:

                        #include "ui_moduletoolboxpage.h"  //< Note that you're including the generated header
                        
                        class MyDialog : public QDialog
                        {
                            Q_OBJECT
                        
                        public:
                            MyDialog(QWidget * parent = NULL);
                        
                        private:
                            Ui::ModuleToolboxPage ui; //< This is the object that represents the form created in the designer
                        }
                        
                        MyDialog::MyDialog(QWidget * parent)
                            : QDialog(parent)
                        {
                            ui.setupUi(this);  //< This line creates all the objects described in the form and attaches them to my dialog. It initializes my dialog with my form
                        }
                        

                        Well this got a bit out of hand with all the code and the image, but I hope it's helpful.

                        Kind regards.

                        Read and abide by the Qt Code of Conduct

                        1 Reply Last reply
                        1
                        • tomyT Offline
                          tomyT Offline
                          tomy
                          wrote on last edited by
                          #15

                          Thank you very much for you comprehensive reply.

                          Before doing them, are those tutorials applicable on my Qt Creator 3.6.0?
                          What is I face incompatibilities between them?

                          As you may know, I'm reading the book C++ GUI Programming With Qt 4 2nd Edition but since that book was confusing me I had to get helps here in forums.
                          Do you suggest that I finish these tuts and then get back to the book?

                          kshegunovK 1 Reply Last reply
                          0
                          • tomyT tomy

                            Thank you very much for you comprehensive reply.

                            Before doing them, are those tutorials applicable on my Qt Creator 3.6.0?
                            What is I face incompatibilities between them?

                            As you may know, I'm reading the book C++ GUI Programming With Qt 4 2nd Edition but since that book was confusing me I had to get helps here in forums.
                            Do you suggest that I finish these tuts and then get back to the book?

                            kshegunovK Offline
                            kshegunovK Offline
                            kshegunov
                            Moderators
                            wrote on last edited by kshegunov
                            #16

                            @tomy
                            Hello,

                            Before doing them, are those tutorials applicable on my Qt Creator 3.6.0?

                            I don't see a reason why they wouldn't be. The screenshot and the generated header I've taken from my own project, and I'm using QtCreator 3.6, so they're very up to date.

                            Do you suggest that I finish these tuts and then get back to the book?

                            No, I've sourced them as "further reading" that should help you with your book and your projects.

                            Kind regards.

                            Read and abide by the Qt Code of Conduct

                            tomyT 1 Reply Last reply
                            0
                            • kshegunovK kshegunov

                              @tomy
                              Hello,

                              Before doing them, are those tutorials applicable on my Qt Creator 3.6.0?

                              I don't see a reason why they wouldn't be. The screenshot and the generated header I've taken from my own project, and I'm using QtCreator 3.6, so they're very up to date.

                              Do you suggest that I finish these tuts and then get back to the book?

                              No, I've sourced them as "further reading" that should help you with your book and your projects.

                              Kind regards.

                              tomyT Offline
                              tomyT Offline
                              tomy
                              wrote on last edited by
                              #17

                              Hello dear kshegunov and thanks for your talks.

                              I appreciate your suggestions and I will certainly try to do them in near future, but what I need now is something else.

                              Please read my above post (the one that I've bookmarked it) and try to answer my questions there.
                              After that part and the other, I understand some main topics and then continue to reading my book and also I do the tuts you helped me by introducing them.
                              Thanks again.

                              K 1 Reply Last reply
                              0
                              • tomyT tomy

                                Hello dear kshegunov and thanks for your talks.

                                I appreciate your suggestions and I will certainly try to do them in near future, but what I need now is something else.

                                Please read my above post (the one that I've bookmarked it) and try to answer my questions there.
                                After that part and the other, I understand some main topics and then continue to reading my book and also I do the tuts you helped me by introducing them.
                                Thanks again.

                                K Offline
                                K Offline
                                koahnig
                                wrote on last edited by
                                #18

                                @tomy
                                You might be the only one seeing the bookmark, AFAIK it is local.
                                Therefore probably nobody is going find and answer your specific question.

                                Even though it is not strongly encouraged in this forum, I suggest that you are starting a new thread with a title already giving an understanding of your problems.

                                Vote the answer(s) that helped you to solve your issue(s)

                                1 Reply Last reply
                                0

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved