Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. How to redirect qml's console.log() to cpp stdout
Forum Updated to NodeBB v4.3 + New Features

How to redirect qml's console.log() to cpp stdout

Scheduled Pinned Locked Moved 3rd Party Software
1 Posts 1 Posters 2.6k Views 1 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.
  • S Offline
    S Offline
    singingsingh
    wrote on last edited by
    #1

    I am using qml( qtCreator ) and cpp (visual studio).

    Usually the error messages are shown to the console, both from cpp and qml.

    My requirement is that I should not have a console.

    So I wrote a window application.

    But when a flag has been set, I should launch a console. And show the corresponding error messages there.

    I have used the following code in a function to set up this.

    @HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
    int hCrt = _open_osfhandle((long) handle_out, _O_TEXT);
    FILE* hf_out = _fdopen(hCrt, "w");
    setvbuf(hf_out, NULL, _IONBF, 128);

    // redirecting the buffers to the file handle
    *stdout = *hf_out;
    *stderr = *hf_out;

    //attach std input to console
    HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
    hCrt = _open_osfhandle((long) handle_in, _O_TEXT);
    FILE* hf_in = _fdopen(hCrt, "r");
    setvbuf(hf_in, NULL, _IONBF, 128);
    *stdin = *hf_in;@

    This will print the error log from stdout and stderr to a console.

    To redirect qt error logs we can use.

    How to redirect qDebug, qWarning, qCritical etc output?

    But how do we redirect the output from console.log() of qml to the console.

    Thanks in advance.

    1 Reply Last reply
    0

    • Login

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