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
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Unsolved The Lounge
18 Posts 7 Posters 5.4k Views
  • 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.
  • 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