Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to redirect all cout to file

How to redirect all cout to file

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 390 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JacobNovitsky
    wrote on last edited by JacobNovitsky
    #1

    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/
    
    sierdzioS 1 Reply Last reply
    0
    • J JacobNovitsky

      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/
      
      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @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.

      (Z(:^

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved