Qt Creator FC23 New Install - No Console Output
-
Hi,
Just installed Fedora 23 on a PC, updated fully, KDE /Plasma desktop, installed Qt-Creator and Qt5 from command line - no issues.
Using the book Application Development with Qt Creator from PACKT - Ray Rischpater.
Simple Hello World application - for console - essentially "cout << "Hello World"; "
Compilation ok - console opens when run, but the console screen is blank, with cursor top left.
File permissions ok - so not sure what the issue is.
Options for project are to run in terminal window.
Is this a library issue i have to install ?.
When installing Qt Creator - automatically pulled down dependencies for qt5.
Any help gratefully received.
Thanks and regards,
Shadders.
-
Do you see the output in the "Application Output" tab in QtCreator?
-
Hi jsulm,
Thanks for the reply.
No, there is no output in the Application Output tab - only the initialisation of the program - "Starting Path_And_Name_Of_Application...".
I can run the binary from the command line and same output - cursor top left only.
I have just installed QT Creator on OpenSuse machine - using the package manager (YaST -> Software Management) - and the same issue.
Thanks and regards,
Shadders.
-
Can you post the source code of your application?
-
Hi jsulm,
Thanks for the reply - code is as follows :
#include <QCoreApplication> #include <iostream> using namespace std; int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); cout << "Hello World!"; return a.exec(); }
This is the exactly as per the book.
Thanks and regards,
Shadders.
-
Change:
std::cout << "Hello World!" << std::flush;
-
@jsulm
Hi jsulm,Thank you - this is working.
Do you know why this is now working and that i have to reference the std namespace specifically ?.
I am just catching back up on C++ after using C# for the past 15 years.
Thanks and regards,
Shadders.
-
@Ni.Sumi
Hi Ni.Sumi,Is this Linux dependent ?.
I just checked the errata page for the book, and no one has provided the change there.
I do not recall having to reference the std namespace explicitly before. So is this a requirement for Qt v5 ?, Linux only ?.
The book is 2013 - so it is possible that C++ requirements have changed.
Once i progress to GUI based application - the reason for knowing this answer may help there too.
Thanks and regards,
Shadders.
-
hi @Shadders ,
AFAIK, you can't specify the using namespace std in Qt application, which is incompatible with the MockCompiler.
When it comes to the GUI Based application, Qt sugguest to use QDebug .
Eg:: #include <QDebug>
--------------------
in code.. qDebug() <<"Somehting "; // it will print out like std::cout and powerful than this -
Hi,
As an update - the
using namespace std;
does work - i played about with the code and all that was required was the endl or flush codeword.
endl places as return as expected, flush outputs the line to console without the return.
Thanks and regards,
Shadders.
-
@Shadders I think the std::flush is needed because just after printing the strinig to the standard output you start the Qt event loop (a.exec()). Standard output is buffered, so you do not know exactly when the buffer is really printed. It looks like sometimes starting event loop prevents the buffer from being flushed.
-
@Shadders
@jsulm is correct. The standard output is a file, and as pretty much any file it is buffered. So you need to explicitly flush the contents sitting in the buffer to see what's been printed.std::endl
will do the flush implicitly after adding the newline. This is not a Qt specific thing (to answer your other question), it applies to non-qt applications as well.On a related note, if you want a "Qt solution" for writing to the standard output, you can use
QTextStream
, like this:QTextStream cout(stdout); cout << "Test string" << endl;
this doesn't require to expand the
std
namespace, or include<iostream>
.@Ni-Sumi said:
AFAIK, you can't specify the using namespace std in Qt application, which is incompatible with the MockCompiler.
You can.
moc
doesn't care about the namespaces. The only issue withusing namespace std;
is the global namespace pollution it introduces, but it's perfectly safe to use it (especially in source files).When it comes to the GUI Based application, Qt sugguest to use QDebug .
Only, and I can't emphasize this enough, for debugging purposes! You shouldn't rely on
qDebug
for production code.Kind regards.
-
Hi jsulm, kshegubnov
Thanks for the extra feedback, much appreciated.
I tried the qDebug function and this does not work for my installation of Fedora 23.
Code i have tried is :
qDebug("6! is %d \n", MathFunctions::factorial(6));
qDebug() << "6! is " << MathFunctions::factorial(6);
qDebug() << "6! is " << MathFunctions::factorial(6) << endl;
and
cout << "6! is " << MathFunctions::factorial(6) << "\n";
The cout version works, but the qDebug version does not print to the console. I replaced the function factorial with a unsigned integer variable, and the same result - no output.
The qDebug example i have used is from the tutorial book - with the third myself adding the endl.
The code compiles ok, and i am using v5.6 of QT Creator.
As such, for the qDebug option, there is no console output.
I have a bug raised with Fedora bugzilla on the library qtdeclarations-devel and qtquickcontrols2 library/package issue - but i do not think that is the issue here.
Any ideas on the console output issues i am experiencing ?
Thanks and regards,
Shadders.
-
That's strange. For me it is working on Ubuntu.
Do you have CONFIG += console in your PRO file? -
@Shadders Look at this and blame Fedora: https://forum.qt.io/topic/54820
-
@Wieland
Smart people those fedora guys ... :D