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. not needed command prompt OS window
Forum Updated to NodeBB v4.3 + New Features

not needed command prompt OS window

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 325 Views
  • 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.
  • R Offline
    R Offline
    Robert M.
    wrote on 19 Mar 2023, 09:25 last edited by
    #1

    I have written C++ application in Qt5 (app runs in Linux and Windows). In Help menu I have Documentation command which shows text that is partially obtained from OS command. When I click Help|Documentation option I see for A MOMENT command prompt OS window, then documentation window. I don't need the first window. How to avoid it?
    Here's how I display documentation in my source code:

    string text;
    ...
    text += exec_system((::installation_dir + ::dir_separator + str2wstr(::dirtyphp_executable)).c_str());

    string exec_system(const wchar_t *cmd) {
    array<char, 128> buffer;
    string result = ""; // cmd's stdout
    string cmdstr = wstr2str(wstring(cmd));
    #ifdef _WIN32
    cmdstr = """ + cmdstr + """; // popen() removes "" in Windows; https://stackoverflow.com/questions/1557091/how-to-call-popen-with-a-pathname-containing-spaces-under-windows-in-c-c/43822734
    #endif
    TRACE("cmdstr: " << cmdstr);
    unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmdstr.c_str(), "r"), pclose);
    if (!pipe) {
    throw runtime_error("popen() failed");
    }
    while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
    result += buffer.data();
    }
    return result;
    }

    C J 2 Replies Last reply 19 Mar 2023, 09:36
    0
    • R Robert M.
      19 Mar 2023, 09:25

      I have written C++ application in Qt5 (app runs in Linux and Windows). In Help menu I have Documentation command which shows text that is partially obtained from OS command. When I click Help|Documentation option I see for A MOMENT command prompt OS window, then documentation window. I don't need the first window. How to avoid it?
      Here's how I display documentation in my source code:

      string text;
      ...
      text += exec_system((::installation_dir + ::dir_separator + str2wstr(::dirtyphp_executable)).c_str());

      string exec_system(const wchar_t *cmd) {
      array<char, 128> buffer;
      string result = ""; // cmd's stdout
      string cmdstr = wstr2str(wstring(cmd));
      #ifdef _WIN32
      cmdstr = """ + cmdstr + """; // popen() removes "" in Windows; https://stackoverflow.com/questions/1557091/how-to-call-popen-with-a-pathname-containing-spaces-under-windows-in-c-c/43822734
      #endif
      TRACE("cmdstr: " << cmdstr);
      unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmdstr.c_str(), "r"), pclose);
      if (!pipe) {
      throw runtime_error("popen() failed");
      }
      while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
      result += buffer.data();
      }
      return result;
      }

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 19 Mar 2023, 09:36 last edited by
      #2

      What should this code do? Open an url? Use QDesktopServices.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      R 1 Reply Last reply 19 Mar 2023, 10:22
      0
      • R Robert M.
        19 Mar 2023, 09:25

        I have written C++ application in Qt5 (app runs in Linux and Windows). In Help menu I have Documentation command which shows text that is partially obtained from OS command. When I click Help|Documentation option I see for A MOMENT command prompt OS window, then documentation window. I don't need the first window. How to avoid it?
        Here's how I display documentation in my source code:

        string text;
        ...
        text += exec_system((::installation_dir + ::dir_separator + str2wstr(::dirtyphp_executable)).c_str());

        string exec_system(const wchar_t *cmd) {
        array<char, 128> buffer;
        string result = ""; // cmd's stdout
        string cmdstr = wstr2str(wstring(cmd));
        #ifdef _WIN32
        cmdstr = """ + cmdstr + """; // popen() removes "" in Windows; https://stackoverflow.com/questions/1557091/how-to-call-popen-with-a-pathname-containing-spaces-under-windows-in-c-c/43822734
        #endif
        TRACE("cmdstr: " << cmdstr);
        unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmdstr.c_str(), "r"), pclose);
        if (!pipe) {
        throw runtime_error("popen() failed");
        }
        while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
        result += buffer.data();
        }
        return result;
        }

        J Offline
        J Offline
        JonB
        wrote on 19 Mar 2023, 09:47 last edited by JonB
        #3

        @Robert-M
        Absolutely as @Christian-Ehrlicher says if QDesktopServices is most appropriate to what you are trying to achieve.

        But just for the record if you do want to execute as OS command yourself. Are you aware that you could do everything you write here using Qt's QProcess, including the ability to read the output from the spawned program, without using any OS-specific calls, pipe(), wide strings, etc.?

        R 1 Reply Last reply 19 Mar 2023, 10:19
        0
        • J JonB
          19 Mar 2023, 09:47

          @Robert-M
          Absolutely as @Christian-Ehrlicher says if QDesktopServices is most appropriate to what you are trying to achieve.

          But just for the record if you do want to execute as OS command yourself. Are you aware that you could do everything you write here using Qt's QProcess, including the ability to read the output from the spawned program, without using any OS-specific calls, pipe(), wide strings, etc.?

          R Offline
          R Offline
          Robert M.
          wrote on 19 Mar 2023, 10:19 last edited by
          #4

          @JonB
          I cannot use QProcess. My project consists of two subprojects: 1. command line program, 2. GUI. In 2nd project I include common.hpp/.cpp library placed in 1st project because I need some functions from it. exec_system() is such function used by both subprojects. I cannot use Qt in 1st subproject.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Robert M.
            wrote on 19 Mar 2023, 10:20 last edited by
            #5

            OS window was displayed because of TRACE(). I commented out TRACE() and I don't see OS window.
            Sorry, my mistake.
            Problem solved.

            1 Reply Last reply
            0
            • C Christian Ehrlicher
              19 Mar 2023, 09:36

              What should this code do? Open an url? Use QDesktopServices.

              R Offline
              R Offline
              Robert M.
              wrote on 19 Mar 2023, 10:22 last edited by
              #6

              @Christian-Ehrlicher
              Not url. I display some text from local PC, not network.

              1 Reply Last reply
              0

              1/6

              19 Mar 2023, 09:25

              • Login

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