QTextStream(stdout) use of undeclared identifier stdout
-
In a Console project I created a class and added :
#include <QTextStream>When I add QTextStream(stdout) the IDE complains about 'use of undeclared identifier stdout' .
I couldn't find any info about this on google or in the documentation.
Anybody could point in the right direction?
Thanks,
Bill -
@JohanSolo said in QTextStream(stdout) use of undeclared identifier stdout:
#include <cstdio>
Yes and no.
Makes no difference if #include <cstdio> is there or not.And what I forgot is that it compiles and runs. Console created and message printed.
It's just the error message.
Meanwhile I realised, this is not the only time this error message comes up:
There is an example project called ThreadedFortuneServer. In the project there is a 'Dialog' class declared. In 'dialog.cpp' the constructor is defined naturally as Dialog::Dialog ....
where the scope declaration ('Dialog' left of the ::) is underlined and the same error message displayed.
Again, the project runs just fine.
(To confirm that it does build and run with the 'error' included, I deleted the build folder)
I closed the project and re-opened it - error still there.
I closed Qt Creator and re-opened it - error still there.This is Linux Mint 19, Cinnamon - if it makes any difference.
If anyone can make sense of this.
-
@Bill52 said in QTextStream(stdout) use of undeclared identifier stdout:
When I add QTextStream(stdout) the IDE complains about 'use of undeclared identifier stdout' .
Your IDE is at fault. The error you observe comes from the code model your IDE uses. The problem is that it doesn't recognize
QTextStream(stdout)
as an anonymous (temporary) object, but instead parses this expression as a constructor-style cast. In any case giving a name to the object is going to fix it, e.g.:QTextStream out(stdout); out << "whatever";
PS.
MSVC 2015 (I think) had the same problem, but at compile time. So the above would be ill-formed if you were to use that compiler. You better stay off of such clever expressions, you may shoot yourself in the foot without even realizing. -
Which Creator version is that? And how did you install it?
For me it works with Creator 4.9, Ubuntu 18.04 and the Clang Code Model enabled:
Usually such errors like yours happen when Clang cannot parse an include file completely (If it helps you: I have dozens of this in different projects).
My code for testing:
#include <QTextStream> int main(int argc, char *argv[]) { QTextStream out(stdout); out << "Hello World" << endl; return 0; }
-
@aha_1980
QT Creator 4.9.0
Based on Qt 5.12.2 (GCC 5.3.1 20160406 (Red Hat 5.3.1-6), 64 bit)
Built on Apr 12 2019 00:19:59
From revision 7885bc899fInstalled from the official QT website:
https://www.qt.io/download-qt-installer ....
OpenSource version. It happened all automatically.Now that you mention, I have a 'clang++:command not found' error when setting the compiler to this.
-
@Bill52 said in QTextStream(stdout) use of undeclared identifier stdout:
Now that you mention, I have a 'clang++:command not found' error when setting the compiler to this.
Where do you have this error?
Note that the Clang Code Model is integrated into Creator, and if you installed with the online installer it should be correctly set up...
WhichUubuntu corresponds this Mint 19 to?
-
@aha_1980 said in QTextStream(stdout) use of undeclared identifier stdout:
@Bill52 said in QTextStream(stdout) use of undeclared identifier stdout:
Now that you mention, I have a 'clang++:command not found' error when setting the compiler to this.
Where do you have this error?
When compiling if the compiler is set to clang. (as it was when I first started up QTCreator. When nothing compiled, I changed it to GCC7.)
Note that the Clang Code Model is integrated into Creator, and if you installed with the online installer it should be correctly set up...
... aaaammm ... unless I changed something .... and don't remember it ...
But the clang compiler never worked. I didn't change it after install. To learn QT I was following the 'notepad' tutorial. When it didn't compile I changed it.WhichUubuntu corresponds this Mint 19 to?
Ubuntu BionicIt's 2:33 AM at this end of the world. If I don't go to sleep I'll faint off the chair.
Thanks for the help for all!Until tomorrow.
-
@Bill52 said in QTextStream(stdout) use of undeclared identifier stdout:
Yes what you are saying but no, it doesn't fix it.
Please provide a small screenshot so we know for sure what we are dealing with.
-
@Bill52 said in QTextStream(stdout) use of undeclared identifier stdout:
... aaaammm ... unless I changed something .... and don't remember it ...
But the clang compiler never worked. I didn't change it after install. To learn QT I was following the 'notepad' tutorial. When it didn't compile I changed it.I'm using gcc for compiling, nevertheless QtCreator uses Clang in a library shipped together with the binary installer for its code model. This is (or say: should be) totally unrelated to other Clang compilers on your system.
To make it short: You can disable the Clang Code Model if you don't want to investigate this issue deeper: Help > About Plugins > Clang Code Model.
Regards
-
@kshegunov
Talking about screen capture, I just noticed an error that appeared under a small yellow triangle on the top of the IDE. It seems to be pointing to the source of the issue.**Warning:** The code model could not parse an included file, which might lead to incorrect code completion and highlighting, for example. os_defines.h:39:10: error: 'features.h' file not found main.cpp:1:1: note: in file included from /home/user/PROGRAMMING/QT/HelloWorld/main.cpp:1: main.cpp:1:10: note: in file included from /home/user/PROGRAMMING/QT/HelloWorld/main.cpp:1: QCoreApplication:1:10: note: in file included from /home/user/Applications/Qt/5.12.3/gcc_64/include/QtCore/QCoreApplication:1: qcoreapplication.h:43:10: note: in file included from /home/user/Applications/Qt/5.12.3/gcc_64/include/QtCore/qcoreapplication.h:43: qglobal.h:45:12: note: in file included from /home/user/Applications/Qt/5.12.3/gcc_64/include/QtCore/qglobal.h:45: type_traits:38:10: note: in file included from /usr/include/c++/7/type_traits:38: c++config.h:533:10: note: in file included from /usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:533:
The 'features.h' is in /usr/include. The path seems to be missing, however:
user@Mint19:~$ cpp -v Using built-in specs. COLLECT_GCC=cpp OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.4.0-1ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04) COLLECT_GCC_OPTIONS='-E' '-v' '-mtune=generic' '-march=x86-64' /usr/lib/gcc/x86_64-linux-gnu/7/cc1 -E -quiet -v -imultiarch x86_64-linux-gnu - -mtune=generic -march=x86-64 -fstack-protector-strong -Wformat -Wformat-security ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/x86_64-linux-gnu/7/include /usr/local/include /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed /usr/include/x86_64-linux-gnu /usr/include End of search list.
says that the path is known.
And I don't know how to go from here. -
@bill52 Just to close this topic in case anybody reads it.
The issue has never been solved. Reinstalling Qt didn't help.Later KDE was installed then Qt 5.13.1 via the offline installer.
After some teething issues it now works. (since yesterday)As a final thought: the offline/online installers failed when i run them from the GUI (dolphin).
The offline installer succeeded when run it from the terminal.