[Interest] How QApplication takes input from Windows Console?

Berkay Elbir berkayelbir at gmail.com
Thu Sep 3 15:45:58 CEST 2015


Hello,

I found the solution. The problem is that when console is closed in project
properties in Visual Studio, Project -> Properties -> Linker -> System ->
SubSystem.

When the Windows Console is turned on so console of my application is
closed then QApplication does not take input from Windows Console.

[image: enter image description here] <http://i.stack.imgur.com/pCpVH.png>

I changed this to Console.

[image: enter image description here] <http://i.stack.imgur.com/Ya3Km.png>

After that, QApplication can take input from Windows Console. But I do not
want to show the console of my application to user. So I hided it in code
by using :

        HWND hwnd = GetConsoleWindow();
        ShowWindow(hwnd, 0);

Therefore, application can take input from user correctly and my console is
hided. I wanted to mention If someone may face this problem. But I still do
not know why QApplication does not take argument when close the console.

On Thu, Sep 3, 2015 at 2:41 PM, Berkay Elbir <berkayelbir at gmail.com> wrote:

> Hello All,
>
> I have a problem about command prompt. I have a C++/Qt GUI desktop
> application on windows 7. But I also need to run this application from
> command prompt for example:
>
> myApp.exe -l myfile -ic.
>
> I can launch and use my app functionality from command prompt successfully
> but if I need to take an input from user on command prompt, I can not take
> inputs. When I enter an input, output is
>
>   Accept values? y(yes)n(no)
>   y
>  'y' is not recognized as an internal or external command,
>   operable program or batch file.
>
> I am taking user input like this:
>
> char userResponse = 'n';
> std::cin >> userResponse;if (userResponse == 'y' || userResponse == 'Y' ){
>     ...             }
>
> emit myWorkDone();return false;
>
> The problem is that program waits on waiting user input line. When
> myWorkDone signal is emitted, application quits for normal conditions.
>
> In main:
>
>  QApplication a(argc,argv);...> QObject::connect(&argProcessor, SIGNAL(finishedProcessor()) ,&a,    > SLOT(quit()),Qt::QueuedConnection);>     >       return a.exec(); // Main application
>
> After that I discovered that QApplication does not listen Windows Console,
> it listens the console of the application.
>
> Is there a way taking input from Windows console in QApplication?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150903/2ee0db49/attachment.html>


More information about the Interest mailing list