not needed command prompt OS window
-
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;
} -
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;
}What should this code do? Open an url? Use QDesktopServices.
-
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;
}@Robert-M
Absolutely as @Christian-Ehrlicher says ifQDesktopServices
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.? -
@Robert-M
Absolutely as @Christian-Ehrlicher says ifQDesktopServices
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.?@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. -
What should this code do? Open an url? Use QDesktopServices.
@Christian-Ehrlicher
Not url. I display some text from local PC, not network.