Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > pl.comp.programming > #34791
| Newsgroups | pl.comp.programming |
|---|---|
| Date | 2022-04-15 06:53 -0700 |
| References | <t2ml98$3a56e$2@portraits.wsisiz.edu.pl> |
| Message-ID | <6a7a1ee7-e05e-43a8-a5ca-cbeec6201cc4n@googlegroups.com> (permalink) |
| Subject | Re: okienko z cmd.exe w Qt C++ |
| From | Adam M <amorawski@magna-power.com> |
On Thursday, April 7, 2022 at 8:26:19 AM UTC-4, Jivanmukta wrote:
> Używam C++ i Qt5.
> Potrzebuje uruchomić pewien program konsolowy z argumentami ale tak,
> żeby było widać okienko cmd.exe z uruchomionym tym programem.
> Próbowałem tak:
>
> std::string terminal = exec_system(L"echo %windir%") +
> "\\system32\\cmd.exe";
> terminal = str_replace("\n", "", str_replace(END_LINE, "", terminal));
> QProcess *process = new QProcess();
> QString exec = QString::fromStdString(terminal);
> QStringList params;
> params << "/C";
> for (std::string s : explode(std::string(" "), command)) {
> params << str_replace("\"", "", s).c_str();
> }
> process->start(exec, params);
> process->waitForFinished();
> delete process;
>
> ale niestety okienko cmd.exe się nie wyświetla.
> Tzn. pojawia się na jakiś czas klepsydra, ale okienka nie ma.
>
> Jak to zrobić?
Do pliku pro dodaj:
CONFIG += console
do pliku CPP ktory startuje twoja aplikacje dodaj
#include <windows.h>
#include <stdio.h>
w funkcji main(..) dodaj
// detach from the current console window
// if launched from a console window, that will still run waiting for the new console (below) to close
// it is useful to detach from Qt Creator's <Application output> panel
FreeConsole();
// create a separate new console window
AllocConsole();
// attach the new console to this application's process
AttachConsole(GetCurrentProcessId());
// reopen the std I/O streams to redirect I/O to the new console
freopen("CON", "w", stdout);
freopen("CON", "w", stderr);
freopen("CON", "r", stdin);
Back to pl.comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar
okienko z cmd.exe w Qt C++ Jivanmukta <jivanmukta@poczta.onet.pl> - 2022-04-07 14:26 +0200
Re: okienko z cmd.exe w Qt C++ Adam M <amorawski@magna-power.com> - 2022-04-15 06:53 -0700
Re: okienko z cmd.exe w Qt C++ Jivanmukta <jivanmukta@poczta.onet.pl> - 2022-04-15 19:10 +0200
Re: okienko z cmd.exe w Qt C++ Adam M <amorawski@magna-power.com> - 2022-04-18 09:30 -0700
Re: okienko z cmd.exe w Qt C++ Jivanmukta <jivanmukta@poczta.onet.pl> - 2022-04-20 11:35 +0200
Re: okienko z cmd.exe w Qt C++ fir <profesor.fir@gmail.com> - 2022-04-27 00:04 -0700
csiph-web