Results 1 to 5 of 5

Thread: Quick help on QProcess

  1. #1
    Join Date
    Jul 2007
    Location
    Scottsdale, AZ USA
    Posts
    17
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Red face Quick help on QProcess

    I am trying to use QProcess to call a perl script. Here is my code:

    Window.h

    Qt Code:
    1. private slots:
    2. void processIT();
    3. void output(const QString &text);
    4. private:
    5. QProcess process;
    To copy to clipboard, switch view to plain text mode 

    Window.cpp

    Qt Code:
    1. void Window::processIT()
    2. {
    3. connect(process,SIGNAL(readyReadStandardOutput()),
    4. this,SLOT(output(const QString &)));
    5. connect(process,SIGNAL(readyReadStandardError(const QString &)),
    6. this,SLOT(output()));
    7. QString path(dirEdit->text());
    8. QString program("perl /home/jim/perlQt/moalq.pl ");
    9. program += path;
    10. process.start(program);
    11. }
    12.  
    13. //....
    14.  
    15. void Window::output(const QString &text)
    16. {
    17. out->append(text);
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 


    my app compiles but I get the following at runtime:
    [HTML]Object::connect: No such slot Window:rocess()[/HTML]


    Any ideas?

  2. #2
    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: Quick help on QProcess

    First of all, this is not correct:
    Qt Code:
    1. connect(process,SIGNAL(readyReadStandardOutput()),
    2. this,SLOT(output(const QString &)));
    To copy to clipboard, switch view to plain text mode 
    A slot may have a shorter signature than the incoming signal, but not the way around.
    Hint: make the parameter for output a default one:
    Qt Code:
    1. void output(const QString &text = "");
    2. ...
    3. connect(process,SIGNAL(readyReadStandardOutput()),
    4. this,SLOT(output()));
    To copy to clipboard, switch view to plain text mode 
    This will work.

    As for the runtime error, that does not make any sense unless you have somewhere in your application a slot called process or you try connecting a signal to an nonexistent process() slot.

    Regards

  3. #3
    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: Quick help on QProcess

    Quote Originally Posted by devilj View Post
    QObject::connect: No such slot Window::process()
    Shouldn't it be processIT()?

  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: Quick help on QProcess

    Quote Originally Posted by jacek View Post
    Shouldn't it be processIT()?
    Yes, that confuses me too.
    Maybe it is just a copy paste error.

    But, if it is processIT, where do you connect to processIT? Could you post that code too?

    Regards

  5. #5
    Join Date
    Jul 2007
    Location
    Scottsdale, AZ USA
    Posts
    17
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Quick help on QProcess

    You guys are right!


    I had this for my process button:
    processButton = createButton(tr("&Process"), SLOT(process()));

    should be ...SLOT(processIT()));

    A slot may have a shorter signature than the incoming signal, but not the way around.
    Hint: make the parameter for output a default one:
    Should I forget about passing a parameter to the output() function.
    in essence:
    Qt Code:
    1. //......
    2. connect(&process,SIGNAL(readyReadStandardOutput()),
    3. this,SLOT([B]output()[/B]));
    4. //.......
    To copy to clipboard, switch view to plain text mode 
    and then setup output as:

    Qt Code:
    1. void Window::output()
    2. {
    3. out->append(QString(process.readyReadStandardOutput()));
    4. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QProcess and Pipes
    By KaptainKarl in forum Qt Programming
    Replies: 1
    Last Post: 10th April 2007, 00:11
  2. QProcess extremely slow on Windows?
    By Pepe in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2007, 01:25
  3. Quoting problem with QProcess
    By the_bis in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2006, 12:24
  4. problem with qprocess
    By deekayt in forum Qt Programming
    Replies: 2
    Last Post: 13th June 2006, 14:30
  5. QProcess in a QThread
    By chombium in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2006, 16:52

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.