Results 1 to 7 of 7

Thread: Problem in studying the official Qt book

  1. #1
    Join Date
    Jan 2016
    Posts
    76
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Problem in studying the official Qt book

    Hello all,

    I'm studying C++ GUI Programming using Qt 4 second edition book. It's apparently the only official book of Qt but it has many defects, for example, it talks about the programs but it doesn't tell us how to create them!

    Do you have this book? If so, please have a look at the Hello program of the first chapter and the programs of the second chapter, like finddialog and GoToCell. How to make those programs run please?
    I'm using Qt creator 3.6.0.

    Thanks in advance.

  2. #2
    Join Date
    Aug 2015
    Posts
    20
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Problem in studying the official Qt book

    This book is written for Qt 4.xx and you are using Qt 5.xx
    To get run this example follow next step:

    1. create a directory Hello

    2. copy the files
    (hello.pro)
    Qt Code:
    1. TEMPLATE = app
    2. SOURCES = hello.cpp
    To copy to clipboard, switch view to plain text mode 
    -and-
    (hello.cpp)
    Qt Code:
    1. #include <QApplication>
    2. #include <QLabel>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7. QLabel *label = new QLabel("Hello Qt!");
    8. label->show();
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 
    -in this directory.

    3. in Creator change the Settings: Tools->Create and Run->Kits->User Defined click on Desktop and change
    Qt-Version: from Qt 5.x in Qt 4.x

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem in studying the official Qt book

    You can alternatively build with Qt5 if you add this line to the .pro file
    Qt Code:
    1. QT += widgets
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  4. #4
    Join Date
    Aug 2015
    Posts
    20
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Problem in studying the official Qt book

    anda_skoa
    adding QT += widgets in *.pro, does it work for all Qt 4 programs?

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

    Default Re: Problem in studying the official Qt book

    Simply run hello.exe

    If I guess correctly, your problem consists in creating the profile file for your project. Therefore:
    (1) Open your Creator.
    (2) Select a new project.
    (3) Select a Qt widget app.
    (4) Add a new file to the project.
    (5) Select a .cpp file (say hello.cpp)
    (6) You get an empty file, perhaps with some pre-typed defines. You can delete all that and enter the contents of hello.cpp from your book.
    (7) Save
    (8) Build
    (9) Run Your exe is the hello.exe in your debug or release directory of the hello project. You can run from the creator, you can run the hello.exe directly from the directory.

    See some tutorial on creating a project in Qt (they are many on the internet). Learn what is a profile file (the .pro file), what is it for, where you find it in your project and how to create/update it yourself. You need to understand this if you want to write projects in Qt.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem in studying the official Qt book

    Quote Originally Posted by kbsk007 View Post
    adding QT += widgets in *.pro, does it work for all Qt 4 programs?
    It is a necessary adjustment for programs that use QtWidgets, because QtWidgets was part of the QtGui library in Qt4 and moved to its own library with Qt5.

    It is not necessary for programs that don't use widgets.

    There are also other changes that might be necessary as some API changed between Qt4 and Qt5.

    Cheers,
    _

  7. #7
    Join Date
    Aug 2015
    Posts
    20
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Problem in studying the official Qt book

    anda_skoa thanks

Similar Threads

  1. How to obtain default Qt options that were used in an official distribution?
    By andrey-rogozhnikov in forum Installation and Deployment
    Replies: 0
    Last Post: 28th November 2013, 10:42
  2. Replies: 1
    Last Post: 2nd January 2012, 23:14
  3. different library names for 'official' and hand-built Qt?
    By akos.maroy in forum Qt Programming
    Replies: 6
    Last Post: 21st July 2009, 02:13
  4. (In-)official Debian/Ubuntu Qt 4.5 package?
    By BastiBense in forum Installation and Deployment
    Replies: 0
    Last Post: 11th March 2009, 10:47

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.