Results 1 to 16 of 16

Thread: C++ GUI Programming

  1. #1
    Join Date
    Jun 2017
    Posts
    19
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default C++ GUI Programming

    I am new to Qt programming, with good understanding of C++.
    I bought Prentice Hall Book, "C++ GUI Programming with Qt 4, Second Edition" by Blanchette and Summerfield. (2008 Published)
    I have downloaded this books source code files from the book publisher's web site.

    I have downloaded and installed on Windows, latest trial version of Qt free for about one month.

    Following is above book's first program:

    // hello.cpp
    #include <QApplication>
    #include <QLabel>

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    QLabel *label = new QLabel("Hello Qt!");
    label->show();
    return app.exec();
    }

    Qt is saying No such file or directory for both QApplication and QLabel

    Is there a way to fix above program, build and run please?

    This book has many excellent Qt programming chapters. I like to be able to load the projects from this book into Qt Creator practice the Qt concepts please
    Thanks,
    Mike

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: C++ GUI Programming

    How did you install QtCreator, stand alone installer or from the Qt installation, or some other way ?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Jun 2017
    Posts
    19
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: C++ GUI Programming

    Installed using Qt installation. Thanks.


    Added after 7 minutes:


    I searched for QAapplication file on my Windows computer C drive and found following path for the QApplication include file:
    C:\Qt\5.9\mingw53_32\include\QtWidgets

    I am trying to add this folder path to the include path in Qt.
    How to add (menu, sub-menu selections?) this QtWidgets include path please?
    Last edited by Mike_m; 23rd June 2017 at 12:28.

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: C++ GUI Programming

    Can you show the "QT" variable assignments in project file i.e. the .pro file.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. #5
    Join Date
    Jun 2017
    Posts
    19
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: C++ GUI Programming

    I have hello.pro file and it has only following two lines:
    TEMPLATE = app
    SOURCES = hello.cpp

  6. #6
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,525
    Thanked 279 Times in 274 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: C++ GUI Programming

    Start new project in Qt Creator with wizard. Then look in the created PRO file.

  7. #7
    Join Date
    Jun 2017
    Posts
    19
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: C++ GUI Programming

    I ran qmake command and now I have following lines in hello.pro
    TEMPLATE = app
    TARGET = hello
    INCLUDEPATH += .

    Can I manually add my QApplication path to above INCLUDEPATH line?

  8. #8
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: C++ GUI Programming

    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  9. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,783
    Thanks
    262
    Thanked 773 Times in 763 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: C++ GUI Programming

    I bought Prentice Hall Book, "C++ GUI Programming with Qt 4, Second Edition" by Blanchette and Summerfield. (2008 Published)
    Be aware that between Qt4 (for which this book was written) and Qt5 (which you are presumably using), the locations of Qt header files and almost the entire Qt source tree layout changed completely. In addition, there are some argument changes to some very basic classes and methods. So examples from Blanchette and Summerfield's book will probably not immediately compile from the downloaded source. The book is otherwise a great way to learn the basics of the C++ side Qt.

    Normally, you do not need to add explicit paths to Qt header files to the .pro file - when you "configure" the project with the correct "kit" in Qt Creator, it will set up the build environment to automatically find what it needs. The INCLUDEPATH directive in the .pro file is usually used for non-Qt headers, like those from external libraries.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  10. #10
    Join Date
    Jun 2017
    Posts
    19
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: C++ GUI Programming

    Santosh: Thank you very much for the program and information. I will go through your example.

    d_stranz:
    Thank you very much for the very useful information. We hope the authors & publisher soon updates the book for Qt5 software.

    Is there any other good Qt5 book with content/information topics similar to the Blanchette and Summerfield book, please?

  11. #11
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,783
    Thanks
    262
    Thanked 773 Times in 763 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: C++ GUI Programming

    Witold Wysota and his colleague Lorenz Haas have written a book "Game Programming using Qt" which really isn't much about game programming at all, but is a basic book on Qt5 C++ and QML. It's the first book I know of that treats Qt Quick and QML in any depth (150 pages). It is pretty well written, and I guess the "game programming" aspect of it is that the examples are based on developing game-like programs. There are a couple of other "cookbook" books, but these aren't as helpful for beginners as Wysota and Haas.

    I have found the books published through Prentice-Hall and Packt to be generally the best quality in terms of content, style, readability. Summerfield has another Qt4 book, "Advanced Qt Programming" which goes into the Model-View architecture in great depth. M-V hasn't changed much between Qt4 and Qt5, so it is still my go-to book when I have questions.
    Last edited by d_stranz; 24th June 2017 at 17:28.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  12. #12
    Join Date
    Jun 2017
    Posts
    19
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: C++ GUI Programming

    d_stranz:
    Thank you for helpful information about good Qt books.

  13. #13
    Join Date
    Jun 2017
    Posts
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: C++ GUI Programming

    I've encountered exactly the same problem - even QApplication is unknown. I've installed the whole Qt package using the installer I've downloaded from the Qt official site.

    Because of this problem I've switched back to an old Qt version: 4.6. The whole package is on a DVD of a Qt 4.6 book I've found in a library. I've borrowed it because it contains a chapter on Qt Creator, and I want to learn to use it, especially use it to debug a program. Now I've made a debug test and it seems to work.

    If you are in Germany, you can try to get the book of Jürgen Wolf "Qt 4.6 Gui-Entwicklung mit C++" (ISBN 978-3-8362-1542-8) from Galileo Computing.

    Weichao

  14. #14
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    256
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: C++ GUI Programming

    Qt Code:
    1. TEMPLATE = app
    2. TARGET = hello
    3. QT = core gui widgets
    To copy to clipboard, switch view to plain text mode 

    The QApplication and QLabel headers were not found because you haven't specified that your app is a windowed one. The above .pro file is for Qt5. If you are using Qt4 then without "widgets":

    Qt Code:
    1. TEMPLATE = app
    2. TARGET = hello
    3. QT = core gui
    To copy to clipboard, switch view to plain text mode 

  15. #15
    Join Date
    Jun 2017
    Posts
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: C++ GUI Programming

    Thank you, Radek! I've read somewhere that the CObject::connect() function for signal-slot in Qt5 is different than that in Qt4. Can only the new one be used in Qt5 or both versions will be accepted? I intend to use Qt4 for a while, since all books I have are for this version.

  16. #16
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    256
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: C++ GUI Programming

    It is backward compatible, therefore, yes. The Qt5 connect() allows you more kinds of connecting. Al long as you won't need Qt5-specific connecting, you can compile both with Qt4 and Qt5. As to the books: they are well usable both for Qt4 and for Qt5. The Qt5 extensions are rather few and you can learn them from online help - but "learning Qt" is "reading the Qt4 books" still.

Similar Threads

  1. Qt C++ CGI programming
    By karankumar1609 in forum General Programming
    Replies: 7
    Last Post: 4th October 2019, 13:56
  2. Is this a QT programming?
    By knuxie1135 in forum Newbie
    Replies: 1
    Last Post: 7th November 2012, 17:09
  3. QT programming on Mac os x
    By invictus in forum General Discussion
    Replies: 6
    Last Post: 5th June 2008, 19:34
  4. Qt programming
    By archanasubodh in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2008, 13:32
  5. QT COM Programming
    By sarav in forum Newbie
    Replies: 5
    Last Post: 24th February 2007, 14:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.