Qt Creator FC23 New Install - No Console Output
-
@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.
-
Hi Shadders,
As @jsulm said, its working...
you can use either
std::cout << "Hello World!" << std::endl;
or
std::cout << "Hello World!" << std::flush; -
@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 -
@Ni.Sumi
Hi Ni.Sumi,Thanks for the guidance, much appreciated.
I will examine the QDebug aspect - this may be mentioned later in the book.
Thanks and regards,
Shadders.
-
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
I also see theqDebug
output on Debian. Perhaps it's redirected to the application output window, could you check that?PS.
Sorry for the late reply, I only just received the notification ... very strange. -
@Shadders Look at this and blame Fedora: https://forum.qt.io/topic/54820
-
@Wieland
Smart people those fedora guys ... :D -
-
@kshegunov
Hi kshequnov,Thanks - application window has nothing - simple console application.
I see that Wieland has provided the answer - essentially debug is set to no for standard installation.
Thanks and regards,
Shadders.
-
@Wieland
Hi Wieland,Thank you for this - much appreciated - changed the ini file to true for debug and is now working.
I have a bug report with Fedora for the QtQuick application - seems to be a library dependency in error in their Fedora 23 repository.
https://bugzilla.redhat.com/show_bug.cgi?id=1337621
Fix seems to be progressing :
https://bodhi.fedoraproject.org/updates/FEDORA-2016-b6db59ce87
Only seems to affect QtQuick for the moment.
Thanks for the help here, much appreciated.
Regards,
Shadders.