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 735 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 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
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on 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
      3
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on 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

        mrjjM 1 Reply Last reply
        3
        • SGaistS SGaist

          Hi,

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

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on 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
          • mrjjM mrjj

            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 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
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              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