Results 1 to 9 of 9

Thread: problems starting process

  1. #1
    Join Date
    Apr 2007
    Location
    Valencia, Spain
    Posts
    30
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default problems starting process

    Hi to everyone,
    I'm doing one gui using Qt3. First I did the gui with QtDesigner and then, using uic command I created the .h and .cpp files. Now I'm using KDevelop as IDE.
    The GUI is really easy, It has only one menu with 4 buttons and one textEdit area where It has to appear all the results of the actions of every button.
    I did like this:
    I have three files: main.cpp, btscanning.h and btscanning.cpp. Everything compiles perfectly.
    In .cpp I have:
    the main function:

    BTScanning::BTScanning( QWidget* parent, const char* name, WFlags fl )
    : QWidget( parent, name, fl )
    {
    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() ) );
    }
    these are the important ones, of course I have more things inside this function.

    and then scan() function:
    void BTScanning::scan()
    {
    QProcess *process = new QProcess(this);
    QByteArray exit;

    process->addArgument("hcitool scan");

    exit = process->readStdout();
    if(!process->start()){
    te_results->insertParagraph(QString("the process is not running"),-1);
    }
    else{
    te_results->insertParagraph(QString(exit),-1);
    }
    te_expl->insertParagraph(QString("The function scanns an area looking for some blueetoth devices that are connected."),-1);

    }

    and It appears in te_results "the process is not running".
    I've been trying a lot of things but allways the same error. The process is not running and I don't know why.Anybody can help me please?
    Thanks a lot.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problems starting process

    Quote Originally Posted by parsito View Post
    exit = process->readStdout();
    if(!process->start()){
    ...
    }
    else {
    ...
    }
    You should first start the process, then read the standard output --- not the other way around.

    Note that the output might not be available immediately, so the best way is to read it in a slot connected to QProcess::readyReadStdout() signal.

  3. #3
    Join Date
    Apr 2007
    Location
    Valencia, Spain
    Posts
    30
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: problems starting process

    Hi jacek,
    I did as you said:

    QProcess *proc = new QProcess(this);
    proc->addArgument("hcitool scan");
    connect(proc, SIGNAL(readyReadStdout()), this, SLOT(scan()));
    if ( !proc->start() ) {
    // error handling
    QMessageBox::critical( 0,
    tr("Fatal error"),
    exit();
    }

    and then the slot:

    void BTScanning::scan()
    {
    te_results->append( proc->readStdout() );
    }
    I found one example and I'm following it, more or less. The problem is:
    btscanning.cpp: In member function ‘virtual void BTScanning::scan()’:
    btscanning.cpp:125: error: ‘proc’ was not declared in this scope
    can you please tell me what I'm doing wrong?

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problems starting process

    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.

  5. #5
    Join Date
    Apr 2007
    Location
    Valencia, Spain
    Posts
    30
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: problems starting process

    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??

  6. #6
    Join Date
    Apr 2007
    Location
    Valencia, Spain
    Posts
    30
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: problems starting process

    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.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problems starting process

    Isn't this by any chance a double thread?
    http://www.qtcentre.org/forum/f-newb...lems-6785.html

  8. #8
    Join Date
    Apr 2007
    Location
    Valencia, Spain
    Posts
    30
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: problems starting process

    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.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problems starting process

    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.

Similar Threads

  1. Check wheter a process is running
    By Lele in forum Qt Programming
    Replies: 1
    Last Post: 15th June 2006, 12:35
  2. QT4 Plugins - problems, problems
    By NormanDunbar in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2006, 15:39
  3. Replies: 2
    Last Post: 26th April 2006, 10:43
  4. How to activate another process?
    By gtthang in forum Qt Programming
    Replies: 6
    Last Post: 3rd February 2006, 07:53
  5. Problems with threads and windows
    By SkripT in forum Qt Programming
    Replies: 15
    Last Post: 16th January 2006, 17:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.