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. Cannot Compile Code...

Cannot Compile Code...

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 740 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.
  • S Offline
    S Offline
    SweetOrange
    wrote on 19 Jul 2018, 19:37 last edited by
    #1

    Hi!
    I am back to C++ and Qt after some time and want to run the
    code found in "C++ GUI Programming with Qt 4" book.
    I have downloaded and installed Qt 5.11.1 for x86, and MINGW 32-bit.

    I get these errors when runing the code:

    0_1532028809275_Qt_hello_project.jpg

    These are my debug settings:

    0_1532028875454_Qt_Project_Settings.jpg

    Here is the code:

    #include <QCoreApplication>
    #include <QtWidgets/QLabel>
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        QLabel *label = new QLabel("Hello Qt!");
        label->show();
    
        return a.exec();
    }
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 19 Jul 2018, 19:53 last edited by
      #2

      Hi
      Most likely the pro file is old.
      make sure you have
      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

      S 1 Reply Last reply 19 Jul 2018, 20:12
      3
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 19 Jul 2018, 19:56 last edited by
        #3

        Hi,

        In addition to the correct answer of @mrjj, your application won’t work. You need a QApplication if you want to use widgets.

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

        M 1 Reply Last reply 19 Jul 2018, 20:10
        3
        • S SGaist
          19 Jul 2018, 19:56

          Hi,

          In addition to the correct answer of @mrjj, your application won’t work. You need a QApplication if you want to use widgets.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 19 Jul 2018, 20:10 last edited by
          #4

          Just as a note
          You can find updated version of the code here
          https://github.com/mutse/qt5-book-code
          That should be easier to use in Qt5

          1 Reply Last reply
          1
          • M mrjj
            19 Jul 2018, 19:53

            Hi
            Most likely the pro file is old.
            make sure you have
            greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

            S Offline
            S Offline
            SweetOrange
            wrote on 19 Jul 2018, 20:12 last edited by
            #5

            @mrjj

            Hi. I have placed

            QT += widgets
            

            at the second line of .pro file.

            0_1532030811894_Qt_hello_projectfile.jpg

            Now code compiles ok but as SGaist mentioned I need a QApplication.

            Here is my corrected code:

            0_1532031153949_qt_hello.jpg

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 19 Jul 2018, 20:14 last edited by
              #6

              Super.
              There is some difference with the includes between 4 and 5.

              1 Reply Last reply
              1

              1/6

              19 Jul 2018, 19:37

              • Login

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