简体   繁体   中英

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

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM