How to redirect all cout to file
-
How to compile and run my cpp program from Qt Creator as I'd do the same with ./my_program > output.txt
Tried to add these lines to pro file, but If build and run using it, my linker does not recognize my shared libs anymore
**# myproject.pro
Your existing project configuration
output_file = /home/j/output.txt
Define a custom target for running the application and redirecting output
custom_target.target = run_and_redirect
custom_target.commands = $$quote($$OUT_PWD/$$TARGET) > $$output_file
custom_target.depends = $(TARGET)Add the custom target to the default target
QMAKE_EXTRA_TARGETS += custom_target
PRE_TARGETDEPS += run_and_redirect**:-1: error: /home/j/MPA-Debug/MPA: error while loading shared libraries: libSpl.so.1: cannot open shared object file: No such file or directory
My current Pro file excluding cpp and headers:
TEMPLATE = app CONFIG += console c++17 CONFIG -= app_bundle CONFIG -= qt CONFIG += warn_on # QMAKE_CXXFLAGS += -fsanitize=address # QMAKE_LFLAGS += -fsanitize=address # # Additional flags to ensure AddressSanitizer works well with Qt # QMAKE_CXXFLAGS += -fno-omit-frame-pointer # QMAKE_CXXFLAGS += -g output_file = /home/j/output.txt # Define a custom target for running the application and redirecting output custom_target.target = run_and_redirect custom_target.commands = $$quote($$OUT_PWD/$$TARGET) > $$output_file custom_target.depends = $(TARGET) # Add the custom target to the default target QMAKE_EXTRA_TARGETS += custom_target PRE_TARGETDEPS += run_and_redirect LIBS += -L/home/j/SPL-Debug/debug/debug -lSpl INCLUDEPATH += /home/j/SPL/ -
How to compile and run my cpp program from Qt Creator as I'd do the same with ./my_program > output.txt
Tried to add these lines to pro file, but If build and run using it, my linker does not recognize my shared libs anymore
**# myproject.pro
Your existing project configuration
output_file = /home/j/output.txt
Define a custom target for running the application and redirecting output
custom_target.target = run_and_redirect
custom_target.commands = $$quote($$OUT_PWD/$$TARGET) > $$output_file
custom_target.depends = $(TARGET)Add the custom target to the default target
QMAKE_EXTRA_TARGETS += custom_target
PRE_TARGETDEPS += run_and_redirect**:-1: error: /home/j/MPA-Debug/MPA: error while loading shared libraries: libSpl.so.1: cannot open shared object file: No such file or directory
My current Pro file excluding cpp and headers:
TEMPLATE = app CONFIG += console c++17 CONFIG -= app_bundle CONFIG -= qt CONFIG += warn_on # QMAKE_CXXFLAGS += -fsanitize=address # QMAKE_LFLAGS += -fsanitize=address # # Additional flags to ensure AddressSanitizer works well with Qt # QMAKE_CXXFLAGS += -fno-omit-frame-pointer # QMAKE_CXXFLAGS += -g output_file = /home/j/output.txt # Define a custom target for running the application and redirecting output custom_target.target = run_and_redirect custom_target.commands = $$quote($$OUT_PWD/$$TARGET) > $$output_file custom_target.depends = $(TARGET) # Add the custom target to the default target QMAKE_EXTRA_TARGETS += custom_target PRE_TARGETDEPS += run_and_redirect LIBS += -L/home/j/SPL-Debug/debug/debug -lSpl INCLUDEPATH += /home/j/SPL/@JacobNovitsky redirecting output is not something to bother qmake (the build system) with.
Either set up Qt Creator run configuration (Project -> Run -> Additional Arguments), or if you want to do it programmatically, use qInstallMessageHandler and there save the messages using QSaveFile or QFile.