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. My first console C++ program on Qt Creator
Forum Update on Monday, May 27th 2025

My first console C++ program on Qt Creator

Scheduled Pinned Locked Moved Solved General and Desktop
35 Posts 6 Posters 9.7k 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.
  • T Offline
    T Offline
    tomy
    wrote on 20 Jan 2019, 21:36 last edited by
    #1

    Hello all,

    I've started learning Linux and it's a good time to use the IDE (Qt Creator 4.8) for C++ console apps too.
    So after creating a Plain C++ Application project I wrote a simple hello world program and ran it.
    Here's the screenshot:

    0_1548020057100_Screenshot from 2019-01-20 16-28-39.png

    What do I get these many errors please?
    I though the IDE has the compiler for C++ console apps too.
    How to solve these please?

    J 1 Reply Last reply 21 Jan 2019, 01:53
    0
    • M Offline
      M Offline
      mrdebug
      wrote on 20 Jan 2019, 21:48 last edited by
      #2

      Here it works

      #include <QCoreApplication>
      #include <iostream>
      #include "QDebug"
      
      using namespace std;
      
      int main(int argc, char *argv[]) {
          cout << "Hello World!!!" << endl;
          qDebug() << "Hello World!!!"; // Qt way
          return 0;
      }
      
      
      Maybe you have got problems with the chosen platform.

      Need programmers to hire?
      www.labcsp.com
      www.denisgottardello.it
      GMT+1
      Skype: mrdebug

      T 1 Reply Last reply 21 Jan 2019, 20:50
      2
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 20 Jan 2019, 21:49 last edited by
        #3

        Hi,

        Can you show your .pro file ?

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

        T 1 Reply Last reply 21 Jan 2019, 20:50
        2
        • T tomy
          20 Jan 2019, 21:36

          Hello all,

          I've started learning Linux and it's a good time to use the IDE (Qt Creator 4.8) for C++ console apps too.
          So after creating a Plain C++ Application project I wrote a simple hello world program and ran it.
          Here's the screenshot:

          0_1548020057100_Screenshot from 2019-01-20 16-28-39.png

          What do I get these many errors please?
          I though the IDE has the compiler for C++ console apps too.
          How to solve these please?

          J Offline
          J Offline
          JKSH
          Moderators
          wrote on 21 Jan 2019, 01:53 last edited by JKSH
          #4

          @tomy said in My first console C++ program on Qt Creator:

          What do I get these many errors please?

          For now, ignore those error messages and try to build and run your application anyway. Does it work? If not, do you see any new error messages?

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

          T 1 Reply Last reply 21 Jan 2019, 20:52
          2
          • M mrdebug
            20 Jan 2019, 21:48

            Here it works

            #include <QCoreApplication>
            #include <iostream>
            #include "QDebug"
            
            using namespace std;
            
            int main(int argc, char *argv[]) {
                cout << "Hello World!!!" << endl;
                qDebug() << "Hello World!!!"; // Qt way
                return 0;
            }
            
            
            Maybe you have got problems with the chosen platform.
            T Offline
            T Offline
            tomy
            wrote on 21 Jan 2019, 20:50 last edited by
            #5

            @mrdebug
            I think it's not plain C++ (at least), it's Qt!

            1 Reply Last reply
            0
            • S SGaist
              20 Jan 2019, 21:49

              Hi,

              Can you show your .pro file ?

              T Offline
              T Offline
              tomy
              wrote on 21 Jan 2019, 20:50 last edited by
              #6

              @SGaist

              Hi, here it is:

              TEMPLATE = app
              CONFIG += console c++11
              CONFIG -= app_bundle
              CONFIG -= qt
              
              SOURCES += \
                      main.cpp
              
              1 Reply Last reply
              0
              • J JKSH
                21 Jan 2019, 01:53

                @tomy said in My first console C++ program on Qt Creator:

                What do I get these many errors please?

                For now, ignore those error messages and try to build and run your application anyway. Does it work? If not, do you see any new error messages?

                T Offline
                T Offline
                tomy
                wrote on 21 Jan 2019, 20:52 last edited by
                #7

                @JKSH

                Of course. I get 6 issues. 5 of them are errors and one warning, as shown in the screenshot in the first post here.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 21 Jan 2019, 20:52 last edited by
                  #8

                  For now try this:

                  1. Remove CONFIG -= qt
                  2. Add QT =

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

                  T 1 Reply Last reply 21 Jan 2019, 21:22
                  2
                  • S SGaist
                    21 Jan 2019, 20:52

                    For now try this:

                    1. Remove CONFIG -= qt
                    2. Add QT =
                    T Offline
                    T Offline
                    tomy
                    wrote on 21 Jan 2019, 21:22 last edited by
                    #9

                    @SGaist
                    I removed the first line.
                    But the second line is half incomplete! Add what to what?

                    aha_1980A 1 Reply Last reply 21 Jan 2019, 21:27
                    0
                    • T tomy
                      21 Jan 2019, 21:22

                      @SGaist
                      I removed the first line.
                      But the second line is half incomplete! Add what to what?

                      aha_1980A Offline
                      aha_1980A Offline
                      aha_1980
                      Lifetime Qt Champion
                      wrote on 21 Jan 2019, 21:27 last edited by
                      #10

                      @tomy Just add the line as @SGaist wrote. This will add no Qt modules, not even core.

                      Qt has to stay free or it will die.

                      1 Reply Last reply
                      0
                      • T Offline
                        T Offline
                        tomy
                        wrote on 21 Jan 2019, 21:38 last edited by
                        #11

                        Here is .pro file:

                        TEMPLATE = app
                        CONFIG += console c++11
                        CONFIG -= app_bundle
                        QT =
                        SOURCES += \
                                main.cpp
                        

                        Still the same errors!

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 21 Jan 2019, 21:41 last edited by
                          #12

                          Did you re-run qmake after modifying the .pro file ?

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

                          T 1 Reply Last reply 21 Jan 2019, 21:43
                          0
                          • S SGaist
                            21 Jan 2019, 21:41

                            Did you re-run qmake after modifying the .pro file ?

                            T Offline
                            T Offline
                            tomy
                            wrote on 21 Jan 2019, 21:43 last edited by tomy
                            #13

                            If using qmake in Linux (Ubuntu) is this way, I did and below is the output. My project is on the Desktop named "hello_world".

                            0_1548109120848_1.png

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 21 Jan 2019, 22:28 last edited by
                              #14

                              What do you get if you call make after that ?

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

                              T 1 Reply Last reply 21 Jan 2019, 22:36
                              0
                              • S SGaist
                                21 Jan 2019, 22:28

                                What do you get if you call make after that ?

                                T Offline
                                T Offline
                                tomy
                                wrote on 21 Jan 2019, 22:36 last edited by
                                #15

                                @SGaist
                                Do you mean I type "make" on the last line?

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on 21 Jan 2019, 22:41 last edited by
                                  #16

                                  Yes, that's it.

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

                                  T 2 Replies Last reply 21 Jan 2019, 22:55
                                  1
                                  • S SGaist
                                    21 Jan 2019, 22:41

                                    Yes, that's it.

                                    T Offline
                                    T Offline
                                    tomy
                                    wrote on 21 Jan 2019, 22:55 last edited by
                                    #17
                                    This post is deleted!
                                    1 Reply Last reply
                                    0
                                    • S SGaist
                                      21 Jan 2019, 22:41

                                      Yes, that's it.

                                      T Offline
                                      T Offline
                                      tomy
                                      wrote on 21 Jan 2019, 23:02 last edited by tomy
                                      #18

                                      @SGaist
                                      Thanks. I did it and it showed the output I wanted on the Terminal.
                                      But still I see the errors and red lines on the code! :(

                                      Why while the program runs successfully does Qt Qreator show them? And how to get rid of them. They are ugly indeed.

                                      0_1548111980062_1.png

                                      1 Reply Last reply
                                      0
                                      • S Offline
                                        S Offline
                                        SGaist
                                        Lifetime Qt Champion
                                        wrote on 21 Jan 2019, 23:09 last edited by
                                        #19

                                        Try changing the code model used by Qt Creator.

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

                                        T 1 Reply Last reply 21 Jan 2019, 23:19
                                        0
                                        • J Offline
                                          J Offline
                                          JKSH
                                          Moderators
                                          wrote on 21 Jan 2019, 23:16 last edited by
                                          #20

                                          @tomy said in My first console C++ program on Qt Creator:

                                          Of course. I get 6 issues. 5 of them are errors and one warning, as shown in the screenshot in the first post here.

                                          The screenshot in your first post shows errors and warnings from the static code analyzer, not from your compiler. We can tell because the red circle and yellow triangles are "hollow". Errors and warnings from your compiler have "filled" circles and triangles.

                                          Try to build and run your code to activate your compiler. Does it run successfully?

                                          Anyway, you are seeing these errors because the static code analyzer thinks you are writing C code (not C++ code) for some reason. You can disable it by clicking Help > About Plugins... and unchecking C++ > Clang Code Model

                                          @tomy said in My first console C++ program on Qt Creator:

                                          If using qmake in Linux (Ubuntu) is this way, I did and below is the output. My project is on the Desktop named "hello_world".

                                          0_1548109120848_1.png

                                          I believe @SGaist meant running qmake from within Qt Creator, when your project is open. The menu item is Build > Run qmake.

                                          Running qmake in the console does not change anything in Qt Creator.

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

                                          1 Reply Last reply
                                          4

                                          1/35

                                          20 Jan 2019, 21:36

                                          • Login

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