0
votes

I'm attempting to write a program for a school project, where I need to make an interface on a linux-based platform, in which I can click a button, that'll then run a set of commands on a raspberry pi connected via wifi.

The RPI is connected via SSH and the wifi network is one created from my own router on which both the PC and the raspberry are the only ones connected. I've given the RPI a static IP adress, so connecting to it outside of QT isn't an issue.

My issue is, that I'm having trouble finding a way to execute even a single command on the RPI using a button in QT.

1
Do you have a program that will show a button? Show us the sourcecode. You can execute commands (such as "ssh raspi some_command") using system() whenever the callback for the button is called. - neuhaus
I do. It's just a simple program that shows 4 different buttons, none of which have any functionality yet. I used one of QT's preset projects to get to where I am now. Can I simply call the system() command mulitple times to post to the RPI? If I've executed the connection with one system() call, will future system() calls then execute those on the RPI? - Emil
Does a function get called when you press a button? Then just use my advice from the previous comment. - neuhaus
It does yes, but I'm having a bit of trouble understanding how to use system(). Say I want to connect to the RPI, and then write to some file that I have on it, say "file.txt" and I want to write "hello world" to the file, how do I do that? - Emil
@neuhaus In a function call to one of the buttons I tried this: QString command ="ssh [email protected]"; system(qPrintable(command)); -- but got an error "Pseudo terminal will not be allocated because stdin is not a terminal" - Emil

1 Answers

2
votes

Use system() to execute a command inside the button's callback function.

Example:

system("ssh raspi \"/bin/echo hello world > file.txt\"");