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. QCoreApplication

QCoreApplication

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 6 Posters 2.5k 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.
  • W Offline
    W Offline
    Willys
    wrote on last edited by
    #1

    Hi!

    Can anyone explain this to me...

    I have the following code..

    #include <QCoreApplication>
    #include <QDebug>

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    qDebug() << "Test";
    return a.exec();
    }

    From the console I run:
    qmake -project
    qmake
    make
    ./app

    On Ubuntu this outputs "Test", but on CentOS the program just sits there with no output.
    If I remove QCoreApplication it outputs "Test" as well, why is that?

    jsulmJ JonBJ 2 Replies Last reply
    0
    • W Willys

      Hi!

      Can anyone explain this to me...

      I have the following code..

      #include <QCoreApplication>
      #include <QDebug>

      int main(int argc, char *argv[])
      {
      QCoreApplication a(argc, argv);
      qDebug() << "Test";
      return a.exec();
      }

      From the console I run:
      qmake -project
      qmake
      make
      ./app

      On Ubuntu this outputs "Test", but on CentOS the program just sits there with no output.
      If I remove QCoreApplication it outputs "Test" as well, why is that?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Willys It's because of

      return a.exec();
      

      This line starts the Qt event loop. Your qDebug output is called before that line.
      Try

      qDebug() << "Test" << flush;
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      W 1 Reply Last reply
      2
      • jsulmJ jsulm

        @Willys It's because of

        return a.exec();
        

        This line starts the Qt event loop. Your qDebug output is called before that line.
        Try

        qDebug() << "Test" << flush;
        
        W Offline
        W Offline
        Willys
        wrote on last edited by
        #3

        @jsulm said in QCoreApplication:

        @Willys It's because of

        return a.exec();
        

        This line starts the Qt event loop. Your qDebug output is called before that line.
        Try

        qDebug() << "Test" << flush;
        

        Hi! Thank you for the reply.
        I got the same result I'm afraid.

        Some more info:
        Works on Ubuntu 18.04, not working on CentOS 7.5.

        .pro file looks like this:

        QT -= gui

        TEMPLATE = app
        TARGET = test
        INCLUDEPATH += .
        CONFIG += c+11 console

        SOURCES += main.cpp

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          may look simple. Just try to put endl at the end of debug. It may be just a buffer issue ?

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          1
          • W Willys

            Hi!

            Can anyone explain this to me...

            I have the following code..

            #include <QCoreApplication>
            #include <QDebug>

            int main(int argc, char *argv[])
            {
            QCoreApplication a(argc, argv);
            qDebug() << "Test";
            return a.exec();
            }

            From the console I run:
            qmake -project
            qmake
            make
            ./app

            On Ubuntu this outputs "Test", but on CentOS the program just sits there with no output.
            If I remove QCoreApplication it outputs "Test" as well, why is that?

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @Willys said in QCoreApplication:

            Unlike other posters I do not believe this will be a "flushing" problem. qDebug() should not be buffering when it writes its output (though of course you should try their suggestions).

            On Ubuntu this outputs "Test", but on CentOS the program just sits there with no output.
            If I remove QCoreApplication it outputs "Test" as well, why is that?

            Do you mean you completely delete the QCoreApplication a(argc, argv); line and do not replace it with anything else? I think you do.

            Rather than the qDebug() not working, it may be/sounds like CentOS is not returning from QCoreApplication a(argc, argv); constructor at all? Either step through code in debugger to see if this is the case, or if you can't do that try something just like

            int main(int argc, char *argv[])
            {
                QCoreApplication a(argc, argv);
                fprintf(stderr, "Test\n");
                return 0;
            }
            

            (add necessary includes for stdio or use cout << ... or something).

            W 1 Reply Last reply
            1
            • aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by
              #6

              It may also be that the qDebug output is redirected to some logfile...

              Qt has to stay free or it will die.

              W 1 Reply Last reply
              5
              • JonBJ JonB

                @Willys said in QCoreApplication:

                Unlike other posters I do not believe this will be a "flushing" problem. qDebug() should not be buffering when it writes its output (though of course you should try their suggestions).

                On Ubuntu this outputs "Test", but on CentOS the program just sits there with no output.
                If I remove QCoreApplication it outputs "Test" as well, why is that?

                Do you mean you completely delete the QCoreApplication a(argc, argv); line and do not replace it with anything else? I think you do.

                Rather than the qDebug() not working, it may be/sounds like CentOS is not returning from QCoreApplication a(argc, argv); constructor at all? Either step through code in debugger to see if this is the case, or if you can't do that try something just like

                int main(int argc, char *argv[])
                {
                    QCoreApplication a(argc, argv);
                    fprintf(stderr, "Test\n");
                    return 0;
                }
                

                (add necessary includes for stdio or use cout << ... or something).

                W Offline
                W Offline
                Willys
                wrote on last edited by
                #7

                @JonB said in QCoreApplication:

                @Willys said in QCoreApplication:

                Unlike other posters I do not believe this will be a "flushing" problem. qDebug() should not be buffering when it writes its output (though of course you should try their suggestions).

                On Ubuntu this outputs "Test", but on CentOS the program just sits there with no output.
                If I remove QCoreApplication it outputs "Test" as well, why is that?

                Do you mean you completely delete the QCoreApplication a(argc, argv); line and do not replace it with anything else? I think you do.

                Rather than the qDebug() not working, it may be/sounds like CentOS is not returning from QCoreApplication a(argc, argv); constructor at all? Either step through code in debugger to see if this is the case, or if you can't do that try something just like

                int main(int argc, char *argv[])
                {
                    QCoreApplication a(argc, argv);
                    fprintf(stderr, "Test\n");
                    return 0;
                }
                

                (add necessary includes for stdio or use cout << ... or something).

                Yes, that works.
                Although if I'm gonna make a console app with QT's classes, signal and slots I need QCoreApplication and return a.exec() if I understand correct?

                J.HilkJ JonBJ 2 Replies Last reply
                0
                • W Willys

                  @JonB said in QCoreApplication:

                  @Willys said in QCoreApplication:

                  Unlike other posters I do not believe this will be a "flushing" problem. qDebug() should not be buffering when it writes its output (though of course you should try their suggestions).

                  On Ubuntu this outputs "Test", but on CentOS the program just sits there with no output.
                  If I remove QCoreApplication it outputs "Test" as well, why is that?

                  Do you mean you completely delete the QCoreApplication a(argc, argv); line and do not replace it with anything else? I think you do.

                  Rather than the qDebug() not working, it may be/sounds like CentOS is not returning from QCoreApplication a(argc, argv); constructor at all? Either step through code in debugger to see if this is the case, or if you can't do that try something just like

                  int main(int argc, char *argv[])
                  {
                      QCoreApplication a(argc, argv);
                      fprintf(stderr, "Test\n");
                      return 0;
                  }
                  

                  (add necessary includes for stdio or use cout << ... or something).

                  Yes, that works.
                  Although if I'm gonna make a console app with QT's classes, signal and slots I need QCoreApplication and return a.exec() if I understand correct?

                  J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #8

                  @Willys this actually confirms, or at least strongy hints, that @aha_1980 suggestion is correct, QDebug seems to redirect the output somehwere else and fprintf prints directly to the console.


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  1
                  • W Willys

                    @JonB said in QCoreApplication:

                    @Willys said in QCoreApplication:

                    Unlike other posters I do not believe this will be a "flushing" problem. qDebug() should not be buffering when it writes its output (though of course you should try their suggestions).

                    On Ubuntu this outputs "Test", but on CentOS the program just sits there with no output.
                    If I remove QCoreApplication it outputs "Test" as well, why is that?

                    Do you mean you completely delete the QCoreApplication a(argc, argv); line and do not replace it with anything else? I think you do.

                    Rather than the qDebug() not working, it may be/sounds like CentOS is not returning from QCoreApplication a(argc, argv); constructor at all? Either step through code in debugger to see if this is the case, or if you can't do that try something just like

                    int main(int argc, char *argv[])
                    {
                        QCoreApplication a(argc, argv);
                        fprintf(stderr, "Test\n");
                        return 0;
                    }
                    

                    (add necessary includes for stdio or use cout << ... or something).

                    Yes, that works.
                    Although if I'm gonna make a console app with QT's classes, signal and slots I need QCoreApplication and return a.exec() if I understand correct?

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #9

                    @Willys
                    The it looks like this is a qDebug()-only issue for you to investigate.

                    1 Reply Last reply
                    1
                    • aha_1980A aha_1980

                      It may also be that the qDebug output is redirected to some logfile...

                      W Offline
                      W Offline
                      Willys
                      wrote on last edited by
                      #10

                      @aha_1980 said in QCoreApplication:

                      It may also be that the qDebug output is redirected to some logfile...

                      That was actually my first thought before I asked this question but I can't seems to find it anywhere.

                      But you seems to be right. I now tried:

                      #include <QCoreApplication>
                      #include <QFile>
                      #include <iostream>

                      int main(int argc, char *argv[])
                      {
                      QCoreApplication a(argc, argv);

                      QFile file("/tmp/test");
                      if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
                          std::cout << "Could not open" << file.fileName().toStdString();
                          return 1;
                      }
                      
                      while(!file.atEnd()) {
                          std::cout << file.readLine().toStdString();
                      }
                      
                      return a.exec();
                      

                      }

                      and it works.

                      So guess I was way off and need to investigate qDebug() on CentOS like JonB said.

                      Thanks guys!

                      JonBJ 1 Reply Last reply
                      1
                      • W Willys

                        @aha_1980 said in QCoreApplication:

                        It may also be that the qDebug output is redirected to some logfile...

                        That was actually my first thought before I asked this question but I can't seems to find it anywhere.

                        But you seems to be right. I now tried:

                        #include <QCoreApplication>
                        #include <QFile>
                        #include <iostream>

                        int main(int argc, char *argv[])
                        {
                        QCoreApplication a(argc, argv);

                        QFile file("/tmp/test");
                        if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
                            std::cout << "Could not open" << file.fileName().toStdString();
                            return 1;
                        }
                        
                        while(!file.atEnd()) {
                            std::cout << file.readLine().toStdString();
                        }
                        
                        return a.exec();
                        

                        }

                        and it works.

                        So guess I was way off and need to investigate qDebug() on CentOS like JonB said.

                        Thanks guys!

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by JonB
                        #11

                        @Willys
                        I hate to suggest this, but are you sure your CentOS version is even compiled for debug...?! Isn't qDebug() a NOOP under Release flags?

                        P.S.
                        Oh, under CentOS put in an additonal qDebug() before QCoreApplication a(argc, argv);, as well as after. Any difference?

                        W 1 Reply Last reply
                        0
                        • JonBJ JonB

                          @Willys
                          I hate to suggest this, but are you sure your CentOS version is even compiled for debug...?! Isn't qDebug() a NOOP under Release flags?

                          P.S.
                          Oh, under CentOS put in an additonal qDebug() before QCoreApplication a(argc, argv);, as well as after. Any difference?

                          W Offline
                          W Offline
                          Willys
                          wrote on last edited by
                          #12

                          @JonB said in QCoreApplication:

                          @Willys
                          I hate to suggest this, but are you sure your CentOS version is even compiled for debug...?! Isn't qDebug() a NOOP under Release flags?

                          P.S.
                          Oh, under CentOS put in an additonal qDebug() before QCoreApplication a(argc, argv);, as well as after. Any difference?

                          It's just a default installation with the minimal ISO.

                          Putting qDebug() << "Test" before QCoreApplication a(argc, argv); works. o.O
                          Just found out that qInfo() works after QCoreApp as well.

                          1 Reply Last reply
                          0
                          • W Offline
                            W Offline
                            Willys
                            wrote on last edited by
                            #13

                            This solves it:
                            https://brendanwhitfield.wordpress.com/2016/06/08/enabling-qdebug-on-fedora/

                            1 Reply Last reply
                            5

                            • Login

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