Declare proc as a member in your class, because the way you did it now is not correct. Now, proc is not visible in the scan function because it is declared in other function.
Declare proc as a member in your class, because the way you did it now is not correct. Now, proc is not visible in the scan function because it is declared in other function.
Hi again,
I created proc as a member of the class. In .h file:
private:
QProcess *proc; //I tried also with public: QProcess *proc;
and then I did like this in the .cpp file:
BTScanning::BTScanning( QWidget* parent, const char* name, WFlags fl )
: QWidget( parent, name, fl )
{
proc = new QProcess(this);
connect( proc, SIGNAL(readyReadStdout()), this, SLOT(scan()) );
te_results = new QTextEdit( this, "te_results" );
te_results->setGeometry( QRect( 250, 180, 341, 281 ) );
pb_scan = new QPushButton( Menu, "pb_scan" );
pb_scan->setGeometry( QRect( 40, 40, 112, 24 ) );
// signals and slots connections
connect( pb_scan, SIGNAL( clicked() ), this, SLOT( scan() ) );
}
the second connect is because I have the button and the action has to be when I click the button of the menu.
The scan() function is now:
void BTScanning::scan()
{
proc->addArgument("hcitool scan");
proc->start();
if (!proc->start())
te_expl->insertParagraph(QString("proc is not running"),-1);
te_results->append(proc->readStdout());
}
and it appears again the message "proc is not running" in te_expl area....
I tried a lot of different combinations but nothing.....can you help me??
I did It!!!!
Now everything works perfectly. What I did is create the object process as a member of the main function ( thanks to marcel ). Then I created another function to connect the process to this slot.
The way of doing It was:
inside the scan() function I created the process, add the arguments and start it and then connect it to the other function using readyReadStdout().
Finally the other function that I created is like this:
QProcess *process = (QProcess*)sender();
while(process->canReadLineStdout()){
te_results->insertParagraph(process->readLineStdout(), -1);
}
if(process->normalExit()){
te_results->insertParagraph(process->readStdout(), -1);
}
thanks to wysota for that.
And thanks to everyone for your help.
Isn't this by any chance a double thread?
http://www.qtcentre.org/forum/f-newb...lems-6785.html
Yes, It is, and I'm sorry about that. I thought that once I started in the newbie forum and people answered me, I can pass to the Qt Programming forum because the other thread was only for the firsts steps. I'm sorry but as I said, is the first time that I write in a forum like this one.
I'm really really sorry. Where I have to continue? Well, I will continue in the newbie forum.
Sorry again to everyone.![]()
Don't worry, it's not a problem. Just don't start multiple threads on the same subject. It's confusing and causes the need to repeat some of the explanations from the other thread and sometimes causes simmilar answers in both threads.
Bookmarks