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 Updated to NodeBB v4.3 + New Features

My first console C++ program on Qt Creator

Scheduled Pinned Locked Moved Solved General and Desktop
35 Posts 6 Posters 9.8k Views 5 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.
  • tomyT Offline
    tomyT Offline
    tomy
    wrote on 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?

    JKSHJ 1 Reply Last reply
    0
    • mrdebugM Offline
      mrdebugM Offline
      mrdebug
      wrote on 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

      tomyT 1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on 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

        tomyT 1 Reply Last reply
        2
        • tomyT tomy

          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?

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on 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

          tomyT 1 Reply Last reply
          2
          • mrdebugM mrdebug

            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.
            tomyT Offline
            tomyT Offline
            tomy
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • SGaistS SGaist

              Hi,

              Can you show your .pro file ?

              tomyT Offline
              tomyT Offline
              tomy
              wrote on 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
              • JKSHJ JKSH

                @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?

                tomyT Offline
                tomyT Offline
                tomy
                wrote on 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
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 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

                  tomyT 1 Reply Last reply
                  2
                  • SGaistS SGaist

                    For now try this:

                    1. Remove CONFIG -= qt
                    2. Add QT =
                    tomyT Offline
                    tomyT Offline
                    tomy
                    wrote on 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
                    0
                    • tomyT tomy

                      @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 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
                      • tomyT Offline
                        tomyT Offline
                        tomy
                        wrote on 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
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 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

                          tomyT 1 Reply Last reply
                          0
                          • SGaistS SGaist

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

                            tomyT Offline
                            tomyT Offline
                            tomy
                            wrote on 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
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 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

                              tomyT 1 Reply Last reply
                              0
                              • SGaistS SGaist

                                What do you get if you call make after that ?

                                tomyT Offline
                                tomyT Offline
                                tomy
                                wrote on last edited by
                                #15

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

                                1 Reply Last reply
                                0
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on 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

                                  tomyT 2 Replies Last reply
                                  1
                                  • SGaistS SGaist

                                    Yes, that's it.

                                    tomyT Offline
                                    tomyT Offline
                                    tomy
                                    wrote on last edited by
                                    #17
                                    This post is deleted!
                                    1 Reply Last reply
                                    0
                                    • SGaistS SGaist

                                      Yes, that's it.

                                      tomyT Offline
                                      tomyT Offline
                                      tomy
                                      wrote on 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
                                      • SGaistS Offline
                                        SGaistS Offline
                                        SGaist
                                        Lifetime Qt Champion
                                        wrote on 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

                                        tomyT 1 Reply Last reply
                                        0
                                        • JKSHJ Offline
                                          JKSHJ Offline
                                          JKSH
                                          Moderators
                                          wrote on 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

                                          • Login

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