🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.programming
Article #217771

Re: okienko z cmd.exe w Qt C++

#217771
From: Jivanmukta
Date: Wed, 20 Apr 2022 09:35
58 lines
3280 bytes
W dniu 15.04.2022 o 19:10, Jivanmukta pisze:
> W dniu 15.04.2022 o 15:53, Adam M pisze:
>> 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);
Chyba nie dość dokładnie się wyraziłem.
Mój program w C++/Qt5 ma własne okienko windowsowe. Chciałbym żeby po 
wyborze pewnej opcji z jego menu uruchomiony został program konsolowy 
(nie w Qt) w osobnym okienku z cmd.exe, tzn. tak, żeby było widać jak 
działa, co wypisuje na ekran. Potem zamknięcie tego osobnego okienka 
powodowałoby powrót do okienka mojego programu zrobionego w Qt.
Technical Details
Message-ID: <t3ok5t$7e22$1@portraits.wsisiz.edu.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!wsisiz.edu.pl!.POSTED.2a00:f41:182c:ba17:b659:b74e:cd27:dc5!not-for-mail
References: <t2ml98$3a56e$2@portraits.wsisiz.edu.pl> <6a7a1ee7-e05e-43a8-a5ca-cbeec6201cc4n@googlegroups.com> <t3c8ts$3advk$1@portraits.wsisiz.edu.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!wsisiz.edu.pl!.POSTED.2a00:f41:182c:ba17:b659:b74e:cd27:dc5!not-for-mail
From: Jivanmukta <jivanmukta@poczta.onet.pl>
Newsgroups: pl.comp.programming
Subject: Re: okienko z cmd.exe w Qt C++
Date: Wed, 20 Apr 2022 11:35:45 +0200
Organization: http://www.wit.edu.pl
Message-ID: <t3ok5t$7e22$1@portraits.wsisiz.edu.pl>
References: <t2ml98$3a56e$2@portraits.wsisiz.edu.pl> <6a7a1ee7-e05e-43a8-a5ca-cbeec6201cc4n@googlegroups.com> <t3c8ts$3advk$1@portraits.wsisiz.edu.pl>
Mime-Version: 1.0
Injection-Date: Wed, 20 Apr 2022 09:35:57 -0000 (UTC)
Injection-Info: portraits.wsisiz.edu.pl; posting-host="2a00:f41:182c:ba17:b659:b74e:cd27:dc5"; logging-data="243778"; mail-complaints-to="abuse@wsisiz.edu.pl"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0
In-Reply-To: <t3c8ts$3advk$1@portraits.wsisiz.edu.pl>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit