🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.programming
Article #217770

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

#217770
From: 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)
Technical Details
Message-ID: <27fd95b0-5a46-474d-8d58-3875c790e3abn@googlegroups.com>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!2.eu.feeder.erje.net!3.us.feeder.erje.net!feeder.erje.net!news.quux.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!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
X-Received: by 2002:a05:6214:29e7:b0:446:6d26:2440 with SMTP id jv7-20020a05621429e700b004466d262440mr839979qvb.118.1650299410510;        Mon, 18 Apr 2022 09:30:10 -0700 (PDT)
X-Received: by 2002:a05:620a:24c4:b0:69e:a0ad:ff5d with SMTP id m4-20020a05620a24c400b0069ea0adff5dmr3061134qkn.11.1650299410257; Mon, 18 Apr 2022 09:30:10 -0700 (PDT)
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!2.eu.feeder.erje.net!3.us.feeder.erje.net!feeder.erje.net!news.quux.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: pl.comp.programming
Date: Mon, 18 Apr 2022 09:30:10 -0700 (PDT)
In-Reply-To: <t3c8ts$3advk$1@portraits.wsisiz.edu.pl>
Injection-Info: google-groups.googlegroups.com; posting-host=71.24.96.225; posting-account=aFGPVQoAAADngh59qlchYygiuB87zBBU
NNTP-Posting-Host: 71.24.96.225
References: <t2ml98$3a56e$2@portraits.wsisiz.edu.pl> <6a7a1ee7-e05e-43a8-a5ca-cbeec6201cc4n@googlegroups.com> <t3c8ts$3advk$1@portraits.wsisiz.edu.pl>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <27fd95b0-5a46-474d-8d58-3875c790e3abn@googlegroups.com>
Subject: Re: okienko z cmd.exe w Qt C++
From: Adam M <amorawski@magna-power.com>
Injection-Date: Mon, 18 Apr 2022 16:30:10 +0000
Lines: 62
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit