Results 1 to 9 of 9

Thread: Call QProcess without GUI

  1. #1
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Call QProcess without GUI

    Hi, what what should i write into the connect function to call the slot updateError() that is into the CallApplication class?
    The connect function in not declared in this scope but i dont need that the callApplication.h derive by QMainWindow or something like that. Is there a work around?
    i want just to call a extern process without any GUI.

    callApplication.h
    Qt Code:
    1. #include <QProcess>
    2.  
    3. class CallApplication
    4. {
    5. public:
    6. CallApplication();
    7. ~CallApplication();
    8. void performApplication();
    9. private slots:
    10. void updateError();
    11. void processFinished(int exitCode, QProcess::ExitStatus exitStatus);
    12. void processError(QProcess::ProcessError error);
    13. public:
    14. QProcess process;
    15. };
    To copy to clipboard, switch view to plain text mode 

    callApplication.cpp
    Qt Code:
    1. #include <callApplication.h>
    2.  
    3. CallApplication::CallApplication()
    4. {
    5. connect(&process, SIGNAL(readyReadStandardError()), /*CallApplication*/, SLOT(updateError())); //<--the reciver is CallApplication
    6. }
    7.  
    8. CallApplication::~CallApplication(){}
    9.  
    10. void CallApplication::performApplication()
    11. {
    12. args << "-resize" << "100x100" << "/home/mattia/image1/1.jpg";
    13. process.start("mogrify", args);
    14. }
    15. void CallApplication::updateError(){}
    16.  
    17. void CallApplication::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
    18. {
    19. }
    20.  
    21.  
    22. void CallApplication::processError(QProcess::ProcessError error)
    23. {
    24. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by mattia; 5th November 2007 at 12:03.

  2. #2
    Join Date
    Oct 2007
    Location
    Munich, Bavaria
    Posts
    144
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Call QProcess without GUI

    simply use: this

  3. #3
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Call QProcess without GUI

    Do you mean in this way?
    Qt Code:
    1. connect(&process, SIGNAL(readyReadStandardError()), this, SLOT(updateError()));
    To copy to clipboard, switch view to plain text mode 
    I get this error: connect was not declered in this scope

  4. #4
    Join Date
    Oct 2007
    Location
    Munich, Bavaria
    Posts
    144
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Call QProcess without GUI

    Try this:
    Qt Code:
    1. QObject::connect(&process, SIGNAL(readyReadStandardError()), this, SLOT(updateError()));
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to DeepDiver for this useful post:

    mattia (5th November 2007)

  6. #5
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Call QProcess without GUI

    now i get the access at the connect function but something still wrong, i get this error:
    no matching function for call to ‘QObject::connect(QProcess*, const char [26], CallApplication* const, const char [15])’

  7. #6
    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: Call QProcess without GUI

    CallApplication doesn't inherit QObject and it lacks Q_OBJECT macro --- without this signals & slots mechanism won't work.

  8. #7
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Call QProcess without GUI

    So, have i to declare the .h class in this way?
    Qt Code:
    1. #include <QProcess>
    2.  
    3. class CallApplication : public QObject
    4. {
    5. Q_OBJECT
    6. public:
    7. CallApplication();
    8. ~CallApplication();
    9. void performApplication();
    10. private slots:
    11. void updateError();
    12. void processFinished(int exitCode, QProcess::ExitStatus exitStatus);
    13. void processError(QProcess::ProcessError error);
    14. public:
    15. QProcess process;
    16. };
    To copy to clipboard, switch view to plain text mode 

  9. #8
    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: Call QProcess without GUI

    Quote Originally Posted by mattia View Post
    So, have i to declare the .h class in this way?
    Yes, and don't forget to re-run qmake.

  10. The following user says thank you to jacek for this useful post:

    mattia (5th November 2007)

  11. #9
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Call QProcess without GUI

    Done! Now it's working. Thanks so much.

Similar Threads

  1. QProcess error to call mogrify
    By mattia in forum Newbie
    Replies: 2
    Last Post: 29th October 2007, 11:46
  2. QProcess and Pipes
    By KaptainKarl in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2007, 23:11
  3. QProcess extremely slow on Windows?
    By Pepe in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2007, 00:25
  4. problem with qprocess
    By deekayt in forum Qt Programming
    Replies: 2
    Last Post: 13th June 2006, 13:30
  5. QProcess / system call not working under linux. Why?
    By johnny_sparx in forum Qt Programming
    Replies: 12
    Last Post: 11th March 2006, 00:32

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.