You could start by reading QProcess docs. There even is a snippet of code there that does what you're trying to achieve.
I completely don't understand why you're creating a new QProcess object in scan()Where do you start the process anyway?
You could start by reading QProcess docs. There even is a snippet of code there that does what you're trying to achieve.
I completely don't understand why you're creating a new QProcess object in scan()Where do you start the process anyway?
Ok, I know that what i put here yesterday doesn't have any sense. After reading the QProcess, I can see that I did wrong from the beginning, isn't It?
I created the .ui file using QTDesigner and then, using uic command I created the header and the .cpp files from that .ui file.
After that I created the main.cpp and It worked perfectly but I started to have problems when I tried that the buttons of the GUI do something.
So I don't have to do my project like I did? I dont have to create the .cpp and .h files?
I'm completely lostI really need your help.....
I'm doing other things. Now I'm creating the new QPocess object into the BTScanning function like this:
BTScanning::BTScanning( QWidget* parent, const char* name, WFlags fl )
: QWidget( parent, name, fl )
{
QProcess *process = new QProcess(this);
then I creat the textEdit:
te_results = new QTextEdit( this, "te_results" );
te_results->setGeometry( QRect( 250, 180, 341, 281 ) );
the button:
pb_save = new QPushButton( Menu, "pb_save" );
pb_save->setGeometry( QRect( 40, 100, 112, 24 ) );
and I connect the button with the slot:
connect( pb_scan, SIGNAL( clicked() ), this, SLOT( scan() ) );
and scan() function is like this:
void BTScanning::scan()
{
QByteArray exit;
process->addArgument("hcitool scan");
exit = process->readStdout();
te_results->insertParagraph(QString(exit),-1);
}
and it appears the error:
btscanning.cpp: In constructor ‘BTScanning::BTScanning(QWidget*, const char*, uint)’:
btscanning.cpp:35: warning: unused variable ‘process’
btscanning.cpp: In member function ‘virtual void BTScanning::scan()’:
btscanning.cpp:97: error: ‘process’ was not declared in this scope
the problem is that if I solve It, If I put the lines:
QByteArray exit;
process->addArgument("hcitool scan");
exit = process->readStdout();
out of the scan() function, into the BTScanning function, and let the scan() function like this:
void BTScanning::scan()
{
te_results->insertParagraph(QString(exit),-1);
}
it appears this error:
btscanning.cpp:100: error: no matching function for call to ‘QString::QString(<unresolved overloaded function type>)’
/usr/include/qt3/qstring.h:746: note: candidates are: QString::QString(QStringData*, bool)
/usr/include/qt3/qstring.h:720: note: QString::QString(int, bool)
/usr/include/qt3/qstring.h:409: note: QString::QString(const std::string&)
/usr/include/qt3/qstring.h:406: note: QString::QString(const char*)
/usr/include/qt3/qstring.h:404: note: QString::QString(const QChar*, uint)
/usr/include/qt3/qstring.h:403: note: QString::QString(const QByteArray&)
/usr/include/qt3/qstring.h:402: note: QString::QString(const QString&)
/usr/include/qt3/qstring.h:401: note: QString::QString(QChar)
/usr/include/qt3/qstring.h:838: note: QString::QString()
but if I do this:
te_results->insertParagraph(QString("exit"),-1);
every time I press the button it appears in the textEdit area the word "exit".
I think that I'm not making any difference between all buttons of the menu.
How I have to do this difference? Each button has to do a different action, but If I create the object process into the BTScanning function I'm not doing this difference....
Last edited by parsito; 9th May 2007 at 15:52. Reason: updated contents
This still sucks. You insert wrong arguments, you don't start the process and you don't wait until it has something to tell you... Try this:Qt Code:
void BTScanning::scan() { QByteArray exit; process->addArgument("hcitool scan"); exit = process->readStdout(); }To copy to clipboard, switch view to plain text mode
Qt Code:
void BTScanning::scan(){ process->addArgument("hcitool"); process->addArgument("scan"); connect(process, SIGNAL(readyReadStdout()), this, SLOT(onProcessReadyRead())); process->start(); } void BTScanning::onProcessReadyRead(){ while(process->canReadLineStdout()){ te_results->insertParagraph(process->readLineStdout(), -1); } if(process->normalExit()){ te_results->insertParagraph(process->readStdout(), -1); } }To copy to clipboard, switch view to plain text mode
Thanks wysota for your help. now everything works perfectly. It compiles and works...thank you very much.
And also thanks for high_flyer for your help at the beginning, you helped me a lot with my firsts steps.
Have you noticed the errors you had made (especially the fact that the process didn't have a chance to start at all)?
yes, now I know how I have to add the arguments to the process and how I have to connect it to the signal and the slot and start it. And also is more clear why I have to wait to read from the process.
But now i have one question, what about if what I want to do is to ask something to the user of the program and then read the answer from the gui?
As I can guess, I have to start the process in the same way as before, and then create another function in the same way as onProcessReadyRead() and inside this function is where I have to read the value, isn't It?
thanks again.
You can write to standard input of a process just like you read from its standard output, if that was your question...
Ok, I can write to the standard input of the process, and also I know how to pass the arguments to the process.
The problem is that I have to ask for three values to the user of the program. The three questions have to appear on the textEdit area of the GUI, one after another, and after each question I have to wait for the answer and get the value that the user types into the textEdit area. I know how to do that the questions appears into the textEdit area, but I don't know how to take the values after each question and put these values into the process as an input value, to add it using addArgument() to the process.
Can anybody help me?
You want the values to be passed as arguments to the process or to be written to the process standard input?
To be passed to the process as arguments, like:
proc->addArgument("value_written_by_the_user");
Ask the user through a dialog or other layout of lineedits about the values and then fire the slot where you start the process and add those values as arguments for the process.
I'm sorry but now I'm completely lost. I created the dialog as you said, to ask the user about the values that I need, and now I have the file fedfangdialog.ui , when I compile the main project as always, It appear automatically two files: redfangdialog.h and redfangdialog.cpp.
And now my question.
What I want that the project does is:
I have one main GUI, with the menu and the textEdit areas. Now, as I can guess, what I have to achieve is that one of the buttons, the redFang button, launch the redfangdialog dialog.
I put in the redfangdialog one button to start all the process, to do that the values that the user enters in the lineedit areas, they have to "come back" to the slot of the button of the main GUI, where I have to add them as arguments to the redfang process.
Another option is that the redfangdialog runs the redfang process with the arguments that the user has entered into the lineEdit areas. The problem is that I still don't know how to run the redfangdialog from the main GUI, when i press the button of the menu.
I don't know how to deal with It![]()
Can anybody help me please?
Bookmarks