Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Header files and general questions.
Forum Updated to NodeBB v4.3 + New Features

Header files and general questions.

Scheduled Pinned Locked Moved Solved General and Desktop
21 Posts 6 Posters 10.1k Views 1 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.
  • U Offline
    U Offline
    Uberlinc
    wrote on last edited by
    #1

    Okay, so I'm trying to teach myself Qt from scratch.
    I have basic C++ skills and so I'm building on these.

    As there appears to be no actual "Learn the latest version of Qt from scratch" I am trying to learn from an outdated book (half the code doesn't work - I suspect a fair bit has changed in 18 years) and updated book which seems less focused on raw code and more focused on the color of the drapes in your new GUI.
    Also, I'm searching for bits and pieces online.

    So, my question is this:

    1. The old book I am working on mainly uses header files in the format #include "qsomethingfile.h" but I notice that there, more often than not, is an available corresponding header file #include <QSomethingFile>

    Which should I use?
    Is one a superset of the other?

    1. One of the books that I am working from is more concerned with using the design tool to create a GUI interface. From what I can work out, data pertaining to these created objects exists in a QML(?) file off to the side and is not represented in hard code in the made files (even though you can create the very same thing in hard code in the main files.)

    Which is the preferred way? GUI interface and then merely reference these objects in the main code, or code up the whole thing from scratch?

    Many thanks,

    Uberlinc.

    JKSHJ 1 Reply Last reply
    0
    • U Uberlinc

      Okay, so I'm trying to teach myself Qt from scratch.
      I have basic C++ skills and so I'm building on these.

      As there appears to be no actual "Learn the latest version of Qt from scratch" I am trying to learn from an outdated book (half the code doesn't work - I suspect a fair bit has changed in 18 years) and updated book which seems less focused on raw code and more focused on the color of the drapes in your new GUI.
      Also, I'm searching for bits and pieces online.

      So, my question is this:

      1. The old book I am working on mainly uses header files in the format #include "qsomethingfile.h" but I notice that there, more often than not, is an available corresponding header file #include <QSomethingFile>

      Which should I use?
      Is one a superset of the other?

      1. One of the books that I am working from is more concerned with using the design tool to create a GUI interface. From what I can work out, data pertaining to these created objects exists in a QML(?) file off to the side and is not represented in hard code in the made files (even though you can create the very same thing in hard code in the main files.)

      Which is the preferred way? GUI interface and then merely reference these objects in the main code, or code up the whole thing from scratch?

      Many thanks,

      Uberlinc.

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @Uberlinc said in Header files and general questions.:

      Okay, so I'm trying to teach myself Qt from scratch.
      I have basic C++ skills and so I'm building on these.

      Hi @Uberlinc, and welcome!

      As there appears to be no actual "Learn the latest version of Qt from scratch" I am trying to learn from an outdated book (half the code doesn't work - I suspect a fair bit has changed in 18 years)

      The Qt engineers tried to make the Qt 4 -> Qt 5 transition as clean and painless as possible, so quite a bit of Qt 4 code is still valid for Qt 5.

      and updated book which seems less focused on raw code and more focused on the color of the drapes in your new GUI.

      Not my favourite approach, but some people like it.

      Also, I'm searching for bits and pieces online.

      This helps too. This forum is a good place for quick questions.

      So, my question is this:

      1. The old book I am working on mainly uses header files in the format #include "qsomethingfile.h" but I notice that there, more often than not, is an available corresponding header file #include <QSomethingFile>

      Which should I use?
      Is one a superset of the other?

      The best way is #include <QSomething>. 99.9% of the time, "QSomething" is the name of the actual class you want to use, so it's easy to remember what to #include.

      And then, if you use your IDE to open the file that you #include'd, you'll find that <QSomething> only has one line which #includes "qsomething.h".

      1. One of the books that I am working from is more concerned with using the design tool to create a GUI interface. From what I can work out, data pertaining to these created objects exists in a QML(?) file off to the side and is not represented in hard code in the made files (even though you can create the very same thing in hard code in the main files.)

      Do you mean .ui.qml files? These didn't exist back in Qt 4.

      Which is the preferred way? GUI interface and then merely reference these objects in the main code, or code up the whole thing from scratch?

      While learning, I think it's more helpful to learn how to code the whole thing from scratch. This way, things are simpler and clearer.

      After I became competent and was able to code everything from scratch without referring to a tutorial, I switched over to the design tool because it's much faster than writing raw code.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      2
      • U Offline
        U Offline
        Uberlinc
        wrote on last edited by
        #3

        Many thanks.

        The two books I am using are:

        1. SAMS Teach Yourself Qt Programming in 24 Hours by Daniel Soln.
          (Publish date is May 2000 even though it's the only one I could find online!)
          I like this book in that it is a step-by-step guide and teaches base coding without using the GUI interface at all.

        2. Qt 5 C++ GUI Programming Cookbook by Lee Zhi Eng.
          (This is up to data, but seems almost exclusively obsessed with the GUI design side of things.)

        I would happily code from scratch, but the SAMS book doesn't seem to work as the examples are old and the compiler throws up errors saying "not declared" etc for many functions within classes even though I've copied the code verbatim.

        For example, I am currently attempting a simple QTableView example.
        The book uses qtableview.h
        It also uses functions such as setCellWidth(int), setCellHeight(int) and setNumCols(int) etc that Qt does not seem to recognise. ('setCellHeight' was not declared in this scope)
        Even if I change the #include to <QTableView> it does not work.

        Is this book of any use to me at all?
        Is there a suitable equivalent to learn Qt C++ (I'd prefer this over other languages) from scratch without having to scrounge the internet for relevant up-to-date examples?

        Thanks,

        Uberlinc.

        JKSHJ 1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          The book to start: http://www.bogotobogo.com/cplusplus/files/c-gui-programming-with-qt-4-2ndedition.pdf
          The 2nd Book: http://www.tka4.org/materials/lib/Articles-Books/C++/Summerfield_M-Advanced_Qt_Programming__Creating_Great_Software_with_C++_and_Qt_4-Prentice_Hall(2010).pdf

          See https://forum.qt.io/topic/70914/a-complete-reference-on-qt5 for a few notes on them

          For Qt5 See:
          https://forum.qt.io/topic/80656/a-new-book-on-qt

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          5
          • U Uberlinc

            Many thanks.

            The two books I am using are:

            1. SAMS Teach Yourself Qt Programming in 24 Hours by Daniel Soln.
              (Publish date is May 2000 even though it's the only one I could find online!)
              I like this book in that it is a step-by-step guide and teaches base coding without using the GUI interface at all.

            2. Qt 5 C++ GUI Programming Cookbook by Lee Zhi Eng.
              (This is up to data, but seems almost exclusively obsessed with the GUI design side of things.)

            I would happily code from scratch, but the SAMS book doesn't seem to work as the examples are old and the compiler throws up errors saying "not declared" etc for many functions within classes even though I've copied the code verbatim.

            For example, I am currently attempting a simple QTableView example.
            The book uses qtableview.h
            It also uses functions such as setCellWidth(int), setCellHeight(int) and setNumCols(int) etc that Qt does not seem to recognise. ('setCellHeight' was not declared in this scope)
            Even if I change the #include to <QTableView> it does not work.

            Is this book of any use to me at all?
            Is there a suitable equivalent to learn Qt C++ (I'd prefer this over other languages) from scratch without having to scrounge the internet for relevant up-to-date examples?

            Thanks,

            Uberlinc.

            JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by JKSH
            #5

            @Uberlinc said in Header files and general questions.:

            1. SAMS Teach Yourself Qt Programming in 24 Hours by Daniel Soln.
              (Publish date is May 2000 even though it's the only one I could find online!)
              I like this book in that it is a step-by-step guide and teaches base coding without using the GUI interface at all.

            Ah... the year 2000 is in the era of Qt 2 (https://en.wikipedia.org/wiki/Qt_version_history ). That book is useless for Qt 5, I'm afraid.

            You can still learn from a Qt 4 book because the transition from Qt 4 to Qt 5 has only minor incompatibilities, but Qt 2 is far too different from Qt 5.

            I would happily code from scratch, but the SAMS book doesn't seem to work as the examples are old and the compiler throws up errors saying "not declared" etc for many functions within classes even though I've copied the code verbatim.

            For example, I am currently attempting a simple QTableView example.
            The book uses qtableview.h
            It also uses functions such as setCellWidth(int), setCellHeight(int) and setNumCols(int) etc that Qt does not seem to recognise. ('setCellHeight' was not declared in this scope)

            setCellWidth(int), setCellHeight(int), and many other functions from Qt 2 no longer exist in Qt 5. The closest living relatives in Qt 5 are setColumnWidth(int, int) and setRowHeight(int, int).

            You can see how QTableView has evolved over the years:

            • https://doc.qt.io/archives/2.3/qtableview.html
            • http://doc.qt.io/qt-5/qtableview.html

            Is there a suitable equivalent to learn Qt C++ (I'd prefer this over other languages) from scratch without having to scrounge the internet for relevant up-to-date examples?

            If you want physical copies of @VRonin's links, see

            • https://www.amazon.com/Programming-Prentice-Source-Software-Development/dp/0132354160
            • https://www.amazon.com/Advanced-Qt-Programming-Creating-Development/dp/0321635906

            Amazon will also suggest a variety of alternative Qt 5 books. I haven't read any of them myself, so I can't comment on their quality or give personal recommendations.

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            3
            • U Offline
              U Offline
              Uberlinc
              wrote on last edited by
              #6

              Many thanks for these suggestions.
              I am quite dismayed that the 70-odd bucks I spent on 2 books has been all in waste and that they are (essentially) of no use to me.

              I am heartened by the support and suggestions you've made.
              I will have a good look at those books that VRonin has suggested.
              They may be prove to be quite useful.
              Thank you!

              I will (obviously) check back in here with irritating questions from time to time when I simply don't get it!

              Many thanks.

              Uberlinc.

              JKSHJ 1 Reply Last reply
              1
              • Pablo J. RoginaP Offline
                Pablo J. RoginaP Offline
                Pablo J. Rogina
                wrote on last edited by
                #7

                @Uberlinc from time to time, whenever you feel the topic/issue you posted is solved, please don't forget to mark it as such. Thank you

                Upvote the answer(s) that helped you solve the issue
                Use "Topic Tools" button to mark your post as Solved
                Add screenshots via postimage.org
                Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0
                • U Uberlinc

                  Many thanks for these suggestions.
                  I am quite dismayed that the 70-odd bucks I spent on 2 books has been all in waste and that they are (essentially) of no use to me.

                  I am heartened by the support and suggestions you've made.
                  I will have a good look at those books that VRonin has suggested.
                  They may be prove to be quite useful.
                  Thank you!

                  I will (obviously) check back in here with irritating questions from time to time when I simply don't get it!

                  Many thanks.

                  Uberlinc.

                  JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by
                  #8

                  @Uberlinc said in Header files and general questions.:

                  I will (obviously) check back in here with irritating questions from time to time when I simply don't get it!

                  Please do! This is what the forum is for.

                  All the best.

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  1 Reply Last reply
                  1
                  • U Offline
                    U Offline
                    Uberlinc
                    wrote on last edited by
                    #9

                    Okay, so I've started on the "C++ GUI Programming with Qt4, Second Edition" book by Jasmin Blanchette and Mark Summerfield."

                    Trying to write out the code and already hitting issues.

                    Not sure if it is simply typos by me (possible, but I've gone over the code and can't find them!) or is Qt4 different sufficiently that even the simplest of code needs some tweaking to make it work?

                    I can post the code I'm trying to use here, and maybe someone can see if it's commensurate with Qt 5 that I am using?

                    If I don't know anything about the language, how can I pick up where the language needs changing for parts where the book is outdated?

                    Thanks.

                    Uberlinc.

                    JKSHJ 1 Reply Last reply
                    0
                    • U Offline
                      U Offline
                      Uberlinc
                      wrote on last edited by
                      #10

                      Okay... so, I got the code to work.
                      I replaced, what was in the book as:

                      class QCheckBox;
                      class QLabel;
                      class QLineEdit;
                      class QPushButton;

                      with:

                      #include <QPushButton>
                      #include <QLabel>
                      #include <QLineEdit>
                      #include <QCheckBox>
                      #include <QBoxLayout>

                      Is this likely to be a mis-print in the original code in the book or has Qt5 changed from Qt4 such that this was correct for the previous version?

                      Thanks.

                      aha_1980A 1 Reply Last reply
                      0
                      • U Uberlinc

                        Okay... so, I got the code to work.
                        I replaced, what was in the book as:

                        class QCheckBox;
                        class QLabel;
                        class QLineEdit;
                        class QPushButton;

                        with:

                        #include <QPushButton>
                        #include <QLabel>
                        #include <QLineEdit>
                        #include <QCheckBox>
                        #include <QBoxLayout>

                        Is this likely to be a mis-print in the original code in the book or has Qt5 changed from Qt4 such that this was correct for the previous version?

                        Thanks.

                        aha_1980A Offline
                        aha_1980A Offline
                        aha_1980
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @Uberlinc it is still very common to have the class forward declarations in the headers and the includes only in the C++ files as it massively speeds up compiling.

                        as a requirement, you can only use pointers or references ro the forward declared classes in the header file.

                        this is nothing Qt specific but common C++ practice.

                        Qt has to stay free or it will die.

                        1 Reply Last reply
                        3
                        • U Uberlinc

                          Okay, so I've started on the "C++ GUI Programming with Qt4, Second Edition" book by Jasmin Blanchette and Mark Summerfield."

                          Trying to write out the code and already hitting issues.

                          Not sure if it is simply typos by me (possible, but I've gone over the code and can't find them!) or is Qt4 different sufficiently that even the simplest of code needs some tweaking to make it work?

                          I can post the code I'm trying to use here, and maybe someone can see if it's commensurate with Qt 5 that I am using?

                          If I don't know anything about the language, how can I pick up where the language needs changing for parts where the book is outdated?

                          Thanks.

                          Uberlinc.

                          JKSHJ Offline
                          JKSHJ Offline
                          JKSH
                          Moderators
                          wrote on last edited by
                          #12

                          @Uberlinc said in Header files and general questions.:

                          Not sure if it is simply typos by me (possible, but I've gone over the code and can't find them!) or is Qt4 different sufficiently that even the simplest of code needs some tweaking to make it work?

                          The one major difference that will likely impact you is that widgets used to be in the Qt GUI module in Qt 4. Now, they are in their own Qt Widgets module in Qt 5.

                          Setting up the project is a bit different, but after that's done the code should still be mostly compatible.

                          how can I pick up where the language needs changing for parts where the book is outdated?

                          The changes are described at http://doc.qt.io/qt-5/portingguide.html. For the beginning parts of the book, you probably won't be affected by anything described here except for the Qt Widgets module change.

                          @Uberlinc said in Header files and general questions.:

                          I replaced, what was in the book as:

                          class QCheckBox;
                          class QLabel;
                          class QLineEdit;
                          class QPushButton;

                          with:

                          #include <QPushButton>
                          #include <QLabel>
                          #include <QLineEdit>
                          #include <QCheckBox>
                          #include <QBoxLayout>

                          Is this likely to be a mis-print in the original code in the book or has Qt5 changed from Qt4 such that this was correct for the previous version?

                          If you examine the book in depth, you will probably find that class QCheckBox; is written in the .h file while #include <QCheckBox> is written in the .cpp file.

                          As @aha_1980 mentioned, the former is called a forward declaration. See the following for more info on how to use them and why:

                          • https://stackoverflow.com/questions/9906402/should-one-use-forward-declarations-instead-of-includes-wherever-possible
                          • https://stackoverflow.com/questions/4757565/what-are-forward-declarations-in-c
                          • https://stackoverflow.com/questions/553682/when-can-i-use-a-forward-declaration

                          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                          1 Reply Last reply
                          5
                          • U Offline
                            U Offline
                            Uberlinc
                            wrote on last edited by
                            #13

                            I've read up a fair bit about forward declarations, and also re-read over the chapter from which I am working.
                            The chapter does indeed mention forward declarations, but I'm still fuzzy as to why the code, as they define it, did not work.

                            If I include the forward declarations of:
                            class QCheckBox;
                            class QLabel;
                            class QLineEdit;
                            class QPushButton;

                            ... that's all well and good, but it doesn't answer where the code for these classes is defined.
                            If you don't include <QCheckbox> ..... <QPushbutton> then where are they kept?

                            The code worked once I commented out these forward declarations and simply included the include file for each of them, but I understand that this is a cumbersome way of doing it.

                            Where else is the full class definition of the above classes if not in its own QFunction include file?

                            If they are included in another, larger include file that the code has already specified, then why didn't the code work?
                            The only include files in the actual specified code are QDialog, QtGUI and QApplication.

                            Thanks for your help.

                            Regards,

                            Uberlinc.

                            aha_1980A JKSHJ 2 Replies Last reply
                            0
                            • U Uberlinc

                              I've read up a fair bit about forward declarations, and also re-read over the chapter from which I am working.
                              The chapter does indeed mention forward declarations, but I'm still fuzzy as to why the code, as they define it, did not work.

                              If I include the forward declarations of:
                              class QCheckBox;
                              class QLabel;
                              class QLineEdit;
                              class QPushButton;

                              ... that's all well and good, but it doesn't answer where the code for these classes is defined.
                              If you don't include <QCheckbox> ..... <QPushbutton> then where are they kept?

                              The code worked once I commented out these forward declarations and simply included the include file for each of them, but I understand that this is a cumbersome way of doing it.

                              Where else is the full class definition of the above classes if not in its own QFunction include file?

                              If they are included in another, larger include file that the code has already specified, then why didn't the code work?
                              The only include files in the actual specified code are QDialog, QtGUI and QApplication.

                              Thanks for your help.

                              Regards,

                              Uberlinc.

                              aha_1980A Offline
                              aha_1980A Offline
                              aha_1980
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @Uberlinc said in Header files and general questions.:

                              I've read up a fair bit about forward declarations, and also re-read over the chapter from which I am working.
                              The chapter does indeed mention forward declarations, but I'm still fuzzy as to why the code, as they define it, did not work.

                              If I include the forward declarations of:
                              class QCheckBox;
                              class QLabel;
                              class QLineEdit;
                              class QPushButton;

                              ... that's all well and good, but it doesn't answer where the code for these classes is defined.
                              If you don't include <QCheckbox> ..... <QPushbutton> then where are they kept?

                              Well, they are kept in their header files, but at the point of forward declaration the compiler just knows that a class QCheckBox exists. Nothing more! you can't do more with the class at this point than declare a pointer to it. that is important to understand.

                              The code worked once I commented out these forward declarations and simply included the include file for each of them,

                              as said, to use the class, you need the include. but that's typically in the C++ file only, not in the header.

                              but I understand that this is a cumbersome way of doing it.

                              it is at least as legal to do so as to do fwd-declaration. you will see both in the wild.

                              Where else is the full class definition of the above classes if not in its own QFunction include file?

                              indeed.

                              If they are included in another, larger include file that the code has already specified, then why didn't the code work?
                              The only include files in the actual specified code are QDialog, QtGUI and QApplication.

                              ????

                              Thanks for your help

                              you're welcome!

                              Qt has to stay free or it will die.

                              1 Reply Last reply
                              4
                              • U Uberlinc

                                I've read up a fair bit about forward declarations, and also re-read over the chapter from which I am working.
                                The chapter does indeed mention forward declarations, but I'm still fuzzy as to why the code, as they define it, did not work.

                                If I include the forward declarations of:
                                class QCheckBox;
                                class QLabel;
                                class QLineEdit;
                                class QPushButton;

                                ... that's all well and good, but it doesn't answer where the code for these classes is defined.
                                If you don't include <QCheckbox> ..... <QPushbutton> then where are they kept?

                                The code worked once I commented out these forward declarations and simply included the include file for each of them, but I understand that this is a cumbersome way of doing it.

                                Where else is the full class definition of the above classes if not in its own QFunction include file?

                                If they are included in another, larger include file that the code has already specified, then why didn't the code work?
                                The only include files in the actual specified code are QDialog, QtGUI and QApplication.

                                Thanks for your help.

                                Regards,

                                Uberlinc.

                                JKSHJ Offline
                                JKSHJ Offline
                                JKSH
                                Moderators
                                wrote on last edited by
                                #15

                                @Uberlinc said in Header files and general questions.:

                                The chapter does indeed mention forward declarations, but I'm still fuzzy as to why the code, as they define it, did not work.

                                Which chapter? We could have a closer look.

                                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                                1 Reply Last reply
                                0
                                • U Offline
                                  U Offline
                                  Uberlinc
                                  wrote on last edited by
                                  #16

                                  C++ GUI Programming with Qt 4, Second Edition
                                  Blanchette and Summerfield
                                  Chapter 2. Creating Dialogs.

                                  VRoninV 1 Reply Last reply
                                  0
                                  • U Uberlinc

                                    C++ GUI Programming with Qt 4, Second Edition
                                    Blanchette and Summerfield
                                    Chapter 2. Creating Dialogs.

                                    VRoninV Offline
                                    VRoninV Offline
                                    VRonin
                                    wrote on last edited by
                                    #17

                                    The code in that chapter is still 100% valid please note the:

                                    The source code is spread across two files: finddialog.h and finddialog.cpp

                                    I think you just put everything in the same file

                                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                    ~Napoleon Bonaparte

                                    On a crusade to banish setIndexWidget() from the holy land of Qt

                                    1 Reply Last reply
                                    3
                                    • U Offline
                                      U Offline
                                      Uberlinc
                                      wrote on last edited by
                                      #18

                                      No, I definitely have, not 2, but 3 (three) files:
                                      finddialog.h
                                      finddialog.cpp
                                      main.cpp

                                      I believe that I have copied the code verbatim, but as it is interspersed between explanatory text, it is possible that I missed the declaration that qualifies these classes.

                                      Can't find where, though!

                                      Can anyone point out in the original text where the declaration is that qualifies the classes in question?
                                      Is it one line like #include <QDoesItAll> or is it a block of several lines that I've missed?

                                      Thanks,

                                      Uberlinc.

                                      1 Reply Last reply
                                      0
                                      • M Offline
                                        M Offline
                                        mpergand
                                        wrote on last edited by mpergand
                                        #19

                                        Hi,

                                        You can download the source code from here:
                                        https://github.com/GaoHongchen/CPPGUIProgrammingWithQt4

                                        The project is in chap02>find folder
                                        You need to proceed two modifications:

                                        • in the find.pro file, add at the top:
                                        QT       += core gui
                                        greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
                                        
                                        • in the findDialog.cpp, at the top do the following:
                                        //#include <QtGui>
                                        #include <QtWidgets>
                                        

                                        That's all

                                        More info here:
                                        https://wiki.qt.io/Transition_from_Qt_4.x_to_Qt5

                                        JKSHJ 1 Reply Last reply
                                        1
                                        • M mpergand

                                          Hi,

                                          You can download the source code from here:
                                          https://github.com/GaoHongchen/CPPGUIProgrammingWithQt4

                                          The project is in chap02>find folder
                                          You need to proceed two modifications:

                                          • in the find.pro file, add at the top:
                                          QT       += core gui
                                          greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
                                          
                                          • in the findDialog.cpp, at the top do the following:
                                          //#include <QtGui>
                                          #include <QtWidgets>
                                          

                                          That's all

                                          More info here:
                                          https://wiki.qt.io/Transition_from_Qt_4.x_to_Qt5

                                          JKSHJ Offline
                                          JKSHJ Offline
                                          JKSH
                                          Moderators
                                          wrote on last edited by JKSH
                                          #20

                                          @mpergand said in Header files and general questions.:

                                          • in the findDialog.cpp, at the top do the following:
                                          //#include <QtGui>
                                          #include <QtWidgets>
                                          

                                          Right.

                                          #include <QtGui> is a quick way to include every single class in the Qt GUI module. Since QCheckBox et al. have been moved to the Qt Widgets module, you can replace this line with #include <QtWidgets> -- this will include every single class in the Qt Widgets module.

                                          To see how this works,

                                          1. Open the code in Qt Creator
                                          2. Hover your mouse over the line #include <QtWidgets>
                                          3. Press F2. You will see that you are actually #include-ing many many classes.

                                          So to summarize:

                                          • Write class QCheckBox; in your .h file, to allow your class to contain a pointer to QCheckBox.
                                          • Write #include <QtWidgets> or #include <QCheckBox> in your .cpp file to allow your code to instantiate a QCheckBox.

                                          Personally, I prefer to include individual classes when developing a proper project. However, including the whole module is quick an easy for rapid prototyping or for tutorials.

                                          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                                          1 Reply Last reply
                                          1

                                          • Login

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