QTextStream not working while running simple console output application Ask Question up vote
-
I am currently working on learning Qt. The book that I am using used Qt 4.7.0 when it was published back in 2011. So I have set up a virtual machine that is running Windows 7 and I used the Qt 4.7.0 MinGW installer and installed the latest version of GCC/G++ using MinGW. Good to go? I suppose. I have set up the build environment to use Bash, qmake, and make commands via the command prompt and have ensured all needed system environment variables are set. My program compiles fine and the executable is built. However, once I run the executable, I get the following output:
QFile::open: File access not specified
Note: I recompiled this program using Qt5 and it all worked fine. However, I am trying to adhere as well as I can to the Qt4 code the book uses so that I do not have to worry about porting over the code to work with Qt 5 standards.
main.cpp
#include <QString> #include <QTextStream> QTextStream cout(stdout); int main(int argc, char** argv) { QString name("John Doe"); cout << name << endl; return 0; }
Project File: test.pro
###################################################################### # Automatically generated by qmake (2.01a) Sun Jun 24 19:06:36 2018 ###################################################################### TEMPLATE = app TARGET = DEPENDPATH += . INCLUDEPATH += . CONFIG += console # Input SOURCES += main.cpp
Running Make in the Directory
C:\Users\John\Desktop\test>make make -f Makefile.Debug make[1]: Entering directory `C:/Users/John/Desktop/test' g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT - nclude/QtCore' -I'../../../../Qt/4.7.0/include/QtGui' -I clude' -I'.' -I'../../../../Qt/4.7.0/include/ActiveQt' - Qt/4.7.0/mkspecs/default' -o debug/main.o main.cpp In file included from c:\qt\4.7.0\include\qtcore\qobject from c:\qt\4.7.0\src\corelib\kernel\qob from c:\qt\4.7.0\include\qtcore\qobject from c:\qt\4.7.0\src\corelib\io\qiodevi from c:\qt\4.7.0\include\qtcore\qiodevi from c:\qt\4.7.0\src\corelib\io\qtextst from c:\qt\4.7.0\include\qtcore\qtextst from c:\qt\4.7.0\include\qtcore\qtextst from main.cpp:2: c:\qt\4.7.0\src\corelib\kernel\qobjectdefs.h:217:20: war literal; C++11 requires a space between literal and stri ix] # define QLOCATION "\0"__FILE__":"QTOSTRING(__LINE__) ^ c:\qt\4.7.0\src\corelib\kernel\qobjectdefs.h:217:32: war literal; C++11 requires a space between literal and stri ix] # define QLOCATION "\0"__FILE__":"QTOSTRING(__LINE__) ^ g++ -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -W -reloc -Wl,-subsystem,console -mthreads -o debug/test.ex /4.7.0/lib' -lQtGuid4 -lQtCored4 make[1]: Leaving directory `C:/Users/John/Desktop/test'
Running Executable
Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\John>cd desktop\test C:\Users\John\Desktop\test>clear C:\Users\John\Desktop\test>cd debug C:\Users\John\Desktop\test\debug>ls main.o test.exe C:\Users\John\Desktop\test\debug>test.exe QFile::open: File access not specified C:\Users\John\Desktop\test\debug>
Makefile
############################################################################# # Makefile for building: test # Generated by qmake (2.01a) (Qt 4.7.0) on: Sun Jun 24 19:12:02 2018 # Project: test.pro # Template: app # Command: c:/Qt/4.7.0/bin/qmake.exe -o Makefile test.pro ############################################################################# first: debug install: debug-install uninstall: debug-uninstall MAKEFILE = Makefile QMAKE = c:/Qt/4.7.0/bin/qmake.exe DEL_FILE = rm CHK_DIR_EXISTS= test -d MKDIR = mkdir COPY = cp COPY_FILE = $(COPY) COPY_DIR = xcopy /s /q /y /i INSTALL_FILE = $(COPY_FILE) INSTALL_PROGRAM = $(COPY_FILE) INSTALL_DIR = $(COPY_DIR) DEL_FILE = rm SYMLINK = DEL_DIR = rmdir MOVE = mv CHK_DIR_EXISTS= test -d MKDIR = mkdir SUBTARGETS = \ debug \ release debug: $(MAKEFILE).Debug FORCE $(MAKE) -f $(MAKEFILE).Debug debug-make_default: $(MAKEFILE).Debug FORCE $(MAKE) -f $(MAKEFILE).Debug debug-make_first: $(MAKEFILE).Debug FORCE $(MAKE) -f $(MAKEFILE).Debug first debug-all: $(MAKEFILE).Debug FORCE $(MAKE) -f $(MAKEFILE).Debug all debug-clean: $(MAKEFILE).Debug FORCE $(MAKE) -f $(MAKEFILE).Debug clean debug-distclean: $(MAKEFILE).Debug FORCE $(MAKE) -f $(MAKEFILE).Debug distclean debug-install: $(MAKEFILE).Debug FORCE $(MAKE) -f $(MAKEFILE).Debug install debug-uninstall: $(MAKEFILE).Debug FORCE $(MAKE) -f $(MAKEFILE).Debug uninstall release: $(MAKEFILE).Release FORCE $(MAKE) -f $(MAKEFILE).Release release-make_default: $(MAKEFILE).Release FORCE $(MAKE) -f $(MAKEFILE).Release release-make_first: $(MAKEFILE).Release FORCE $(MAKE) -f $(MAKEFILE).Release first release-all: $(MAKEFILE).Release FORCE $(MAKE) -f $(MAKEFILE).Release all release-clean: $(MAKEFILE).Release FORCE $(MAKE) -f $(MAKEFILE).Release clean release-distclean: $(MAKEFILE).Release FORCE $(MAKE) -f $(MAKEFILE).Release distclean release-install: $(MAKEFILE).Release FORCE $(MAKE) -f $(MAKEFILE).Release install release-uninstall: $(MAKEFILE).Release FORCE $(MAKE) -f $(MAKEFILE).Release uninstall Makefile: test.pro ../../../../Qt/4.7.0/mkspecs/default/qmake.conf ../../../../Qt/4.7.0/mkspecs/qconfig.pri \ ../../../../Qt/4.7.0/mkspecs/modules/qt_webkit_version.pri \ ../../../../Qt/4.7.0/mkspecs/features/qt_functions.prf \ ../../../../Qt/4.7.0/mkspecs/features/qt_config.prf \ ../../../../Qt/4.7.0/mkspecs/features/exclusive_builds.prf \ ../../../../Qt/4.7.0/mkspecs/features/default_pre.prf \ ../../../../Qt/4.7.0/mkspecs/features/win32/default_pre.prf \ ../../../../Qt/4.7.0/mkspecs/features/debug.prf \ ../../../../Qt/4.7.0/mkspecs/features/debug_and_release.prf \ ../../../../Qt/4.7.0/mkspecs/features/default_post.prf \ ../../../../Qt/4.7.0/mkspecs/features/win32/default_post.prf \ ../../../../Qt/4.7.0/mkspecs/features/win32/console.prf \ ../../../../Qt/4.7.0/mkspecs/features/win32/rtti.prf \ ../../../../Qt/4.7.0/mkspecs/features/win32/exceptions.prf \ ../../../../Qt/4.7.0/mkspecs/features/win32/stl.prf \ ../../../../Qt/4.7.0/mkspecs/features/shared.prf \ ../../../../Qt/4.7.0/mkspecs/features/warn_on.prf \ ../../../../Qt/4.7.0/mkspecs/features/qt.prf \ ../../../../Qt/4.7.0/mkspecs/features/win32/thread.prf \ ../../../../Qt/4.7.0/mkspecs/features/moc.prf \ ../../../../Qt/4.7.0/mkspecs/features/resources.prf \ ../../../../Qt/4.7.0/mkspecs/features/uic.prf \ ../../../../Qt/4.7.0/mkspecs/features/yacc.prf \ ../../../../Qt/4.7.0/mkspecs/features/lex.prf \ ../../../../Qt/4.7.0/mkspecs/features/incredibuild_xge.prf \ ../../../../Qt/4.7.0/mkspecs/features/include_source_dir.prf $(QMAKE) -o Makefile test.pro ../../../../Qt/4.7.0/mkspecs/qconfig.pri: ../../../../Qt/4.7.0/mkspecs/modules/qt_webkit_version.pri: ../../../../Qt/4.7.0/mkspecs/features/qt_functions.prf: ../../../../Qt/4.7.0/mkspecs/features/qt_config.prf: ../../../../Qt/4.7.0/mkspecs/features/exclusive_builds.prf: ../../../../Qt/4.7.0/mkspecs/features/default_pre.prf: ../../../../Qt/4.7.0/mkspecs/features/win32/default_pre.prf: ../../../../Qt/4.7.0/mkspecs/features/debug.prf: ../../../../Qt/4.7.0/mkspecs/features/debug_and_release.prf: ../../../../Qt/4.7.0/mkspecs/features/default_post.prf: ../../../../Qt/4.7.0/mkspecs/features/win32/default_post.prf: ../../../../Qt/4.7.0/mkspecs/features/win32/console.prf: ../../../../Qt/4.7.0/mkspecs/features/win32/rtti.prf: ../../../../Qt/4.7.0/mkspecs/features/win32/exceptions.prf: ../../../../Qt/4.7.0/mkspecs/features/win32/stl.prf: ../../../../Qt/4.7.0/mkspecs/features/shared.prf: ../../../../Qt/4.7.0/mkspecs/features/warn_on.prf: ../../../../Qt/4.7.0/mkspecs/features/qt.prf: ../../../../Qt/4.7.0/mkspecs/features/win32/thread.prf: ../../../../Qt/4.7.0/mkspecs/features/moc.prf: ../../../../Qt/4.7.0/mkspecs/features/resources.prf: ../../../../Qt/4.7.0/mkspecs/features/uic.prf: ../../../../Qt/4.7.0/mkspecs/features/yacc.prf: ../../../../Qt/4.7.0/mkspecs/features/lex.prf: ../../../../Qt/4.7.0/mkspecs/features/incredibuild_xge.prf: ../../../../Qt/4.7.0/mkspecs/features/include_source_dir.prf: qmake: qmake_all FORCE @$(QMAKE) -o Makefile test.pro qmake_all: FORCE make_default: debug-make_default release-make_default FORCE make_first: debug-make_first release-make_first FORCE all: debug-all release-all FORCE clean: debug-clean release-clean FORCE distclean: debug-distclean release-distclean FORCE -$(DEL_FILE) Makefile check: first debug-mocclean: $(MAKEFILE).Debug $(MAKE) -f $(MAKEFILE).Debug mocclean release-mocclean: $(MAKEFILE).Release $(MAKE) -f $(MAKEFILE).Release mocclean mocclean: debug-mocclean release-mocclean debug-mocables: $(MAKEFILE).Debug $(MAKE) -f $(MAKEFILE).Debug mocables release-mocables: $(MAKEFILE).Release $(MAKE) -f $(MAKEFILE).Release mocables mocables: debug-mocables release-mocables FORCE: $(MAKEFILE).Debug: Makefile $(MAKEFILE).Release: Makefile
-
Hi and welcome to devnet,
Which book would that be ?
In any case, you really should consider doing it with Qt 5. Qt 4 has already reached end of life since some times now and learning Qt should rather be using Qt 5. Most of the books about Qt are for the fourth series but are still relevant with some tweaks here and there.
-
@Johnx8664 Learning Qt4 at this point would be a waste of your time. Like @SGaist said it's long past it's end of life. Qt5 is 12 major releases into it's life cycle now and 5 years old now.
I would grab a book on Qt5, or I find it's pretty easy to learn Qt just from the docs that come with it. If you know C++ well (and you should if you are tackling Qt), then you should be fine learning from the Qt Assistant docs. There are a lot of examples and tutorials in there as well.