Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Getting "Hello world" to work on Qt5
Forum Updated to NodeBB v4.3 + New Features

Getting "Hello world" to work on Qt5

Scheduled Pinned Locked Moved Qt Creator and other tools
7 Posts 5 Posters 12.0k 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.
  • E Offline
    E Offline
    ee_martin
    wrote on last edited by
    #1

    Hi! Please forgive me, but I am a complete newbie with Qt and am having silly troubles. I have downloaded Qt 5.0.2 and installed it on my Windows XP laptop. The installation is the default, and includes MinGW. I have the book "C++ GUI Programming with Qt4" (yes, 4, not 5), and I am trying to get the first simple test program to go. The code in "hello.cpp" is:

    #include <QtWidgets/QApplication>
    #include <QtWidgets/QLabel>

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

    I have learned to make it <QtWidgets/QApplication>, not <QApplication>, etc.

    I have run qmake -project to get hello.pro, which is:

    ######################################################################

    Automatically generated by qmake (3.0) Wed 19. Jun 18:52:41 2013

    ######################################################################

    TEMPLATE = app
    TARGET = hello
    INCLUDEPATH += .

    Input

    SOURCES += hello.cpp

    Then "qmake hello.pro" seems to run successfully (or at least silently).

    I have learned that I need to set up a file "make.bat" that says:

    @echo off
    mingw32-make %*

    Having done that I get the following errors on running "make"

    E:\hello>make
    mingw32-make -f Makefile.Release
    mingw32-make[1]: Entering directory 'E:/hello'
    g++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release\hello.exe release/hello.o -lmingw32 -lqtmain -LE:\Qt-5.0.2\5.0.2\mingw47_32\lib -lQt5Gui -lQt5Core -llibEGL -llibGLESv2 -lgdi32 -luser32
    release/hello.o:hello.cpp:(.text+0x59): undefined reference to _imp___ZN12QApplicationC1ERiPPci' release/hello.o:hello.cpp:(.text+0xbe): undefined reference to _imp___ZN6QLabelC1ERK7QStringP7QWidget6QFlagsIN2Qt10WindowTypeEE' release/hello.o:hello.cpp:(.text+0xfe): undefined reference to _imp___ZN7QWidget4showEv'
    release/hello.o:hello.cpp:(.text+0x10c): undefined reference to _imp___ZN12QApplication4execEv' release/hello.o:hello.cpp:(.text+0x122): undefined reference to _imp___ZN12QApplicationD1Ev'
    release/hello.o:hello.cpp:(.text+0x1be): undefined reference to `_imp___ZN12QApplicationD1Ev'
    collect2.exe: error: ld returned 1 exit status
    Makefile.Release:77: recipe for target 'release\hello.exe' failed
    mingw32-make[1]: *** [release\hello.exe] Error 1
    mingw32-make[1]: Leaving directory 'E:/hello'
    makefile:34: recipe for target 'release' failed
    mingw32-make: *** [release] Error 2


    I am running all this from a Command prompt on my Windows XP laptop. The PATH is:

    PATH=E:\Qt-5.0.2\5.0.2\mingw47_32\bin;E:\Qt-5.0.2/Tools/MinGW\bin;C:\DOS\BIN;C:\MinGW\bin;C:\DOS\CL;C:\DOS\EMACS;C:\WINDOWS;C:\WINDOWS\SYSTEM32;C:\GNUPLOT\BIN

    I would be very grateful if someone would take the time to tell me, using simple words, how I could get this test program to work. It is safe to assume that I know nothing, so please be very clear what has to be done.

    Thanks!

    Martin

    1 Reply Last reply
    0
    • C Offline
      C Offline
      code_fodder
      wrote on last edited by
      #2

      Hi martin,

      As a complete newb, I would make it easier on yourself and use the SDK. You can download from:

      http://qt-project.org/downloads

      You can choose the one with the compiler you want, and it comes with Qt Creator and will allow you to create project templates with the "new project" option.

      Once you download and install it you just open QtCreator. Then do

      File->new file/project --> Qt GUI application.

      Then select all the defaults and you are done!

      Then you can just add your label code into the main.cpp main() function and then run it. You will have the same as you are trying to do with none of that hassle.

      In one minute I created a GUI app put your label code into it and had a hello world app running :)

      Otherwise if you want to go on the manual path, you can still do this and then look at how the project is setup it may help you...

      1 Reply Last reply
      0
      • JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        Hi Martin,

        I agree with code_fodder. Using Qt Creator will be a lot easier.

        [quote author="ee_martin" date="1371665147"]I have learned to make it <QtWidgets/QApplication>, not <QApplication>, etc.[/quote]<QApplication> is better than <QtWidgets/QApplication> -- it will make your code more portable in the future.

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

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qxoz
          wrote on last edited by
          #4

          Hi Martin,
          Some useful links:
          "https://github.com/mutse/qt5-book-code":https://github.com/mutse/qt5-book-code
          "Transition_from_Qt_4.x_to_Qt5":http://qt-project.org/wiki/Transition_from_Qt_4.x_to_Qt5

          1 Reply Last reply
          0
          • E Offline
            E Offline
            ee_martin
            wrote on last edited by
            #5

            Folks,
            Thanks so much for your advice. I'm on holiday right now with few facilities, but I'll be trying out your ideas next week.

            I have to admit I'm a bit of a control freak. You'll understand what I mean when I say that virtually all my programming is done in assembler (time-critical applications of small microcontrollers). I'd like to be able to work at the command line level, so I do want to chase that up. However, the SDK does sound like the lesser-pain route!

            Let's hope that totally-out-of-my-control (Eeeek!) method works ...

            Martin

            1 Reply Last reply
            0
            • C Offline
              C Offline
              code_fodder
              wrote on last edited by
              #6

              lol...good luck :)

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

                Hi,

                You are missing:

                @QT += widgets@

                in your pro file.

                Since you want to use the command line, the qmake manual will be a good starting point

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

                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