0

Ok, so I am executing a program ./led.sh present in my SBC6845, from my host system using a qt-C++ program. This program basically connects my SBC to my host system. It is the equivalent of "hyperterminal" or "Minicom". I obtained this program (the example code) "uartassistant" inside "qextserialport-1.2rc.zip" from http://code.google.com/p/qextserialport/ .

I came across this link: Running shell command in QT c++ in ubuntu , while searching how to execute a shell command from inside the qt program. I tried and succeeded in executing ./led.sh. Thanks to the link.

I declared

void someaction(); // in the dialog.h

then in dialog.cpp I add this

connect(ui->pushButton, SIGNAL(clicked()), SLOT(someaction()));

and this

void Dialog::someaction() {

QString command = "sh ./led.sh\r\n"; const char* command2;
command2 = command.toLocal8Bit().data(); port->write(command2);

I was able to do the ledflash in my SBC.

But the problem occurs when I try to stop ./led.sh, I am unable to do so in the uartassistant (bugs, need modification, still working). But for the time being I am trying to make another pushbutton_1 and put something like "Ctrl+Z" inside and ask ./led.sh to stop. I came across some other links which I am unable to put due to low reputation points. I have no idea how to use SIGTERM / kill option[from other links] inside qt app and execute on pushbutton click. Say if I used kill how would I determine the pidof of multiple such pushbutton actions and assign whom to kill.

Also I would like to add that my SBC has ash [Almquist shell]. So it being low memory clone of Bourne shell, I don't know if it would support normal commands for exiting led.sh.

Community
  • 1
  • 1
rNov
  • 61
  • 1
  • 15
  • Looks like there are two problems mixed up here: how to send a `Ctrl-Z` (assuming that works) and how to trigger that from a button. To separate the 2 problems, create a function that sends the Ctrl-Z. – MSalters Apr 02 '13 at 14:34
  • That was what I was thinking to do. If I know what is the equivalent of ctrl-Z (kill i guess?) I can put it in a function and call it from a button. – rNov Apr 03 '13 at 07:14

2 Answers2

1

I have no idea how to use SIGTERM / kill option[from other links] inside qt app and execute on pushbutton click.

As with so much, Qt gives you an intuitive abstraction that allows you to not have to worry about any of this, namely QProcess. In your case you'd want something like this:

QProcess proc;
proc.start("led.sh");
...

//handle Ctrl-Z event
proc.close();

The first answer here has several other techniques for executing more complicated shell commands.

Community
  • 1
  • 1
Matt Phillips
  • 9,465
  • 8
  • 44
  • 75
0

I have found a temporary solution for my problem. I am yet to try the qprocess action.

In dialog.h I added another function:

void someotheraction();

then in dialog.cpp I did this:

connect(ui->pushButton_2,SIGNAL(clicked()), SLOT(someotheraction()));

and this:

void Dialog::someotheraction()
{
  QString command = "\x001a \r\n"; const char* command2; // Ctrl-Z = \x001a
  command2 = command.toLocal8Bit().data();
  port->write(command2);}

The fifth reply here gave me the idea. I don't know how, but it did the job maybe some one can explain it better.

rNov
  • 61
  • 1
  • 15