Qt Creator stdin for command line with Deploy to Remote Linux Host

别来无恙 提交于 2019-12-07 18:14:23

问题


I am using the Remote Deploy feature of Qt Creator to launch my simple command line application on an embedded Linux target board. My test application is extremely simple and asks the user to print his/her name. It crosscompiles, transfers to the board, and launches and the 'Application Output' window near the bottom of Qt Creator shows the 'Type your name:' prompt, but I cannot type anywhere and provide stdin to the application running remotely through Qt Creator.

How can I accomplish this within Qt Creator? Can I somehow manipulate the deploy 'arguments' to connect a device to provide stdin to my command line app? I also cannot launch the application remotely by checking the 'run in terminal' checkbox under Projects > Run Configuration since it is not available for remote deployments.

Code:

#include <iostream>

using namespace std;

int main() {
    cout << "Enter a number: ";
    int nb;
    cin>>nb;
    cout << "Here is your number:" << nb << endl;
    return 0;
}

Application Output in Qt Creator:

Killing remote process(es)...
Starting remote process ...
Remote process started.
Enter a number: d

回答1:


I found out that there is no way to provide stdin to an app launched by qt creator from within the IDE.

I did try a few things and it looks like a named pipe works just fine. Luckily it’s included with Busybox so it’s on my board.

To use it you launch the app remotely from Qt Creator using the ‘Alternate executable on device’ option under ‘run settings’ and pipe the last line of the named pipe to your c++ program expecting stdin. So your ‘Alternate executable on device looks like:

cd /home/test; tail -f mypipe | ./test3 –qws

‘test3’ is my program and /home/testis the location of the executable.

Then open up 1 extra ubuntu terminal and SSH to the board. Now create a named pipe called ‘mypipe’:

mkfifo mypipe

And when your program expecting stdin launches and waits for input, you can echo the input from that other terminal into the named pipe and your program will take it as stdin:

echo ‘2’ > mypipe



回答2:


There are more options in Debug > Start Debug submenu. And there's one that you need: Attach to Running Debug Server. It does open this neat little window:

As you can see, there's a lot of parameters, even "Run in terminal" option, but it doesn't work on my machine for some reason. Don't forget to properly set your local path to executable binary and kit device settings. I would also recommend you to bind hotkey for AttachToRemoteServer command in Environment > Keyboard settings.

After that the only thing you need to do is to run gdbserver on your remote device:

gdbserver :<port> <executable>

Running process does have a proper stdin and stdout streams and you can interact with your application in terminal via SSH session.



来源:https://stackoverflow.com/questions/11869281/qt-creator-stdin-for-command-line-with-deploy-to-remote-linux-host

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!