🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pl.comp.programming
6 messages
6 total messages Started by Jivanmukta Thu, 07 Apr 2022 12:26
okienko z cmd.exe w Qt C++
#217767
Author: Jivanmukta
Date: Thu, 07 Apr 2022 12:26
23 lines
1607 bytes
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ć?
Re: okienko z cmd.exe w Qt C++
#217768
Author: Adam M
Date: Fri, 15 Apr 2022 13:53
48 lines
2934 bytes
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);
Re: okienko z cmd.exe w Qt C++
#217769
Author: Jivanmukta
Date: Fri, 15 Apr 2022 17:10
52 lines
2753 bytes
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);
> 

A jak wystartować aplikację?
Re: okienko z cmd.exe w Qt C++
#217770
Author: Adam M
Date: Mon, 18 Apr 2022 16:30
53 lines
3793 bytes
On Friday, April 15, 2022 at 1:10:22 PM UTC-4, Jivanmukta wrote:
> 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); 
> >
> A jak wystartować aplikację?
Najlepiej to zrobic z cmd lub ps (albo z Microsoft Terminal jesli to Win 10) - teoretycznie konsola powinna byc dostepna nawet przy normalnym starcie z GUI (przez double-cick na ikone) ale czesto konsola sie pojawia ale bez informacji (tylko okienko konsoli i nic wiecej przynajmniej w QT pomiedzy 5.5 i 5.11 - w 6 za wyjatkiem prostych testow nic jeszcze nie robilem)
Re: okienko z cmd.exe w Qt C++
#217771
Author: 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.
Re: okienko z cmd.exe w Qt C++
#217772
Author: fir
Date: Wed, 27 Apr 2022 07:04
13 lines
2241 bytes
środa, 20 kwietnia 2022 o 11:35:59 UTC+2 Jivanmukta napisał(a):
> 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.

jest to dosc zabawna rzecz, i wielu ludzi o tym nie wiem ale to czy do programu
w windows jest dolaczone w tle konsolowe okienko decyduje pole w pliku exe co znaczy ze mozesz do kazdego w zasadzie chyba programu na windzie ta konsole wlaczyc lub wylaczyc zminiajac mu to pole w hex edytorze lub prostym programikiem

czy ta konsole sie daje ukrywac i pokazywac w runtime z menu programu 
to nie wiem (prawdopodobnie tak ale nie chce mi sie szukac)
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads