QCoreApplication
-
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
./appOn 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? -
@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.
TryqDebug() << "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 consoleSOURCES += main.cpp
-
may look simple. Just try to put endl at the end of debug. It may be just a buffer issue ?
-
@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 fromQCoreApplication 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 likeint main(int argc, char *argv[]) { QCoreApplication a(argc, argv); fprintf(stderr, "Test\n"); return 0; }
(add necessary includes for
stdio
or usecout << ...
or something). -
It may also be that the qDebug output is redirected to some logfile...
-
@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 fromQCoreApplication 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 likeint main(int argc, char *argv[]) { QCoreApplication a(argc, argv); fprintf(stderr, "Test\n"); return 0; }
(add necessary includes for
stdio
or usecout << ...
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? -
@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!
-
@Willys
I hate to suggest this, but are you sure your CentOS version is even compiled for debug...?! Isn'tqDebug()
a NOOP under Release flags?P.S.
Oh, under CentOS put in an additonalqDebug()
beforeQCoreApplication a(argc, argv);
, as well as after. Any difference? -
@JonB said in QCoreApplication:
@Willys
I hate to suggest this, but are you sure your CentOS version is even compiled for debug...?! Isn'tqDebug()
a NOOP under Release flags?P.S.
Oh, under CentOS put in an additonalqDebug()
beforeQCoreApplication 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. -