qtconsole beginner question creator 17
-
not sure if this is the right section, so apologies if this should be somewhere else.
i'm a beginner and had a question about creator 17. i think the install went fine, i've tested it using one of the demo example projects.
i started learning qt a couple years back but stopped before i got going properly. i remember using the following code to start with a console application:
#include <QCoreApplication> #include <QDebug> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); qInfo() << "Hello World!"; return a.exec(); }
this doesn't do anything in creator 17, so my first question is why doesn't this work?
also, how can i amend it so that it does?
thanks.
-
@joshim may it be you arehit by: https://bugreports.qt.io/browse/QTCREATORBUG-33102 ?
Which plattform are you on, and which Qt Version are you using? Is there anything in the Application Output?
Regards
-
@joshim may it be you arehit by: https://bugreports.qt.io/browse/QTCREATORBUG-33102 ?
Which plattform are you on, and which Qt Version are you using? Is there anything in the Application Output?
Regards
linux manjaro (arch based) qt 6.9.1
application output:
22:12:39: Starting /home/joshim/Documents/036_code/untitled9/build/Desktop-Debug/untitled9...
nothing happens after that. it doesn't produce a terminal output, but also doesn't crash. it will remain like this until i force the stop.
the hello world in the help documentation works ok:
#include <stdio.h> int main() { printf("Hello, world\n"); return 0; }
which shows:
22:01:35: Starting /home/joshim/Documents/036_code/untitled9/build/Desktop-Debug/untitled9... Hello, world
that's why i thought the first example must be written out wrong, but you think there might be something up with my install?
-
linux manjaro (arch based) qt 6.9.1
application output:
22:12:39: Starting /home/joshim/Documents/036_code/untitled9/build/Desktop-Debug/untitled9...
nothing happens after that. it doesn't produce a terminal output, but also doesn't crash. it will remain like this until i force the stop.
the hello world in the help documentation works ok:
#include <stdio.h> int main() { printf("Hello, world\n"); return 0; }
which shows:
22:01:35: Starting /home/joshim/Documents/036_code/untitled9/build/Desktop-Debug/untitled9... Hello, world
that's why i thought the first example must be written out wrong, but you think there might be something up with my install?
@joshim
You do not say where you are looking for the output (which you either get or do not get)? Since this is a "console" application have you made settings in Creator for this project to open a console window or what? Does that window appear in both cases? When run from Creator theprintf()
output will appear in the opened console window but I think theqInfo()
output will only appear in Creator's Application Output pane or similar. -
@joshim I think your program simple stucks in the
a.exec();
loop. TheqInfo()
output might be buffered, that's why you don't see anything.Regards
-
@aha_1980 said in qtconsole beginner question creator 17:
The qInfo() output might be buffered, that's why you don't see anything.
Nah, I really don't think so!
qDebug()
/qInfo()
etc. would be pretty useless if their output gets buffered!@Christian-Ehrlicher said in qDebug instant output?:
Since qDebug() is using stdio for it's output the os and std specific io buffering is taking effect
Also I think, underlying to QDebug << is a QTextStream which is most definitely buffered.
https://codebrowser.dev/qt5/qtbase/src/corelib/io/qdebug.cpp.html
-
@Christian-Ehrlicher said in qDebug instant output?:
Since qDebug() is using stdio for it's output the os and std specific io buffering is taking effect
Also I think, underlying to QDebug << is a QTextStream which is most definitely buffered.
https://codebrowser.dev/qt5/qtbase/src/corelib/io/qdebug.cpp.html
@J.Hilk
I have usedqDebug()
/qInfo()
for years without it ever doing anything other than immediate output, no buffering, else it would be "useless".If it makes any difference, both output a newline at the end of any string passed to them. stderr should be totally unbuffered, stdio should be at most line-buffered. I don't even know whether you have access to any
QDebug()
'sQTextStream
even if you had to flush it. And IIRCqDebug()
etc. create and destroy aQDebug
instance or similar --- and the destructor outputs a newline which is why you always get one.@joshim
Remove thereturn a.exec();
, so your Qt console app exits after theqInfo()
. That should certainly flush if there really is any buffering going on! Do you see the output anywhere after exiting the program like this? -
@joshim
You do not say where you are looking for the output (which you either get or do not get)? Since this is a "console" application have you made settings in Creator for this project to open a console window or what? Does that window appear in both cases? When run from Creator theprintf()
output will appear in the opened console window but I think theqInfo()
output will only appear in Creator's Application Output pane or similar.@JonB i've tried this with "run in terminal" checked and unchecked. same result with either.
the printf() output appears in the application output tab in creator, not the terminal tab
i removed return a.exec(); and now the application output shows:
17:14:31: Starting /home/joshim/Documents/036_code/untitled9/build/Desktop-Debug/untitled9... 17:14:31: The command "/home/joshim/Documents/036_code/untitled9/build/Desktop-Debug/untitled9" finished successfully.
so it doesn't hang anymore, but there is no output in the terminal tab within creator.
-
ok so judging by everyone's responses i realised it wasn't that the code was out of date and that creator 17 needed updated instructions, rather there was something wrong with my setup.
so in case anyone else has this problem with gnome desktop environment, the culprit is gnome's default terminal app "Console". this app has a binary called kxg and i couldn't figure out what instruction to give to creator to launch it. so i installed gnome-terminal and made this the default terminal app. under environment variables in the manage kits section, the terminal command is gnome-terminal -x. this seems to have solved the problem.
thanks to everyone who replied. it set me in the right direction!
-