Results 1 to 12 of 12

Thread: Object::connect: No such signal QProces?????

  1. #1
    Join Date
    Nov 2009
    Posts
    59
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Object::connect: No such signal QProces?????

    header file
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QProcess>
    6. #include <QPushButton>
    7. #include <qmessagebox.h>
    8. #include <qdebug.h>
    9. namespace Ui {
    10. class MainWindow;
    11. }
    12.  
    13. class MainWindow : public QMainWindow {
    14. Q_OBJECT
    15. public:
    16. MainWindow(QWidget *parent = 0);
    17. ~MainWindow();
    18.  
    19. protected:
    20. void changeEvent(QEvent *e);
    21.  
    22. private:
    23. Ui::MainWindow *ui;
    24. QProcess *pr;
    25. signals:
    26. void StartProcess(bool timerout);
    27. public slots:
    28. void SaveLog(bool timerout);
    29. private:
    30.  
    31. };
    32.  
    33. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 
    source file
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. pr=new QProcess();
    10. connect(pr,SIGNAL(StartProcess(bool)),this, SLOT(SaveLog(bool )));
    11. }
    12.  
    13. MainWindow::~MainWindow()
    14. {
    15. delete ui;
    16. }
    17.  
    18. //void MainWindow::StartProcess(){}
    19. void MainWindow::SaveLog(bool timerout){
    20. emit StartProcess(timerout);
    21. pr->start("E:\\test\\ttttt.exe");
    22.  
    23. if(pr->waitForFinished(3000)==false){
    24. QMessageBox::warning(
    25. this,
    26. tr("timeout"),
    27. tr("timeout") );
    28.  
    29.  
    30. }
    31.  
    32.  
    33. }
    34. void MainWindow::changeEvent(QEvent *e)
    35. {
    36. QMainWindow::changeEvent(e);
    37. switch (e->type()) {
    38. case QEvent::LanguageChange:
    39. ui->retranslateUi(this);
    40. break;
    41. default:
    42. break;
    43. }
    44. }
    To copy to clipboard, switch view to plain text mode 
    but when i run code
    it displayes the erors
    Qt Code:
    1. Starting C:\Users\nthung\Documents\test1\debug\test1.exe...
    2. Object::connect: No such signal QProcess::StartProcess(bool) in mainwindow.cpp:10
    3. Object::connect: (receiver name: 'MainWindow')
    4. C:\Users\nthung\Documents\test1\debug\test1.exe exited with code 0
    To copy to clipboard, switch view to plain text mode 
    Help me?
    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Object::connect: No such signal QProces?????

    It is a signal of your class and not QProcess! So use "this, SIGNAL(...)".

  3. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Object::connect: No such signal QProces?????

    You are doing something weird, connecting a slot to a signal, which is emitted from this slot ... I don't really understand what is the purpose.
    What are you trying to achieve ?

  4. The following user says thank you to stampede for this useful post:

    nthung (6th October 2011)

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Object::connect: No such signal QProces?????

    See Time out for a QProcess to see the origin of this odyssey.

    If you want to start a program, terminate it after 3 seconds if it has not finished already, and do not mind the whole application being unresponsive during that time then it need be no more complicated than this (Nish said this in the other thread):
    Qt Code:
    1. // An example, long running program on my machine
    2. QString cmd = "/bin/ls";
    3. QStringList args = QStringList() << "-lR" << "/";
    4.  
    5. const int timeoutPeriod = 3000;
    6.  
    7. QProcess proc;
    8. proc.start(cmd, args);
    9. bool finished = proc.waitForFinished(timeoutPeriod);
    10. if (!finished)
    11. proc.terminate();
    To copy to clipboard, switch view to plain text mode 

    If you want your application to remain responsive, perhaps reading the output of the sub program, during the time out period than you need to be more involved.

    Which is it?
    Last edited by ChrisW67; 5th October 2011 at 23:58.

  6. #5
    Join Date
    Nov 2009
    Posts
    59
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Object::connect: No such signal QProces?????

    Quote Originally Posted by stampede View Post
    You are doing something weird, connecting a slot to a signal, which is emitted from this slot ... I don't really understand what is the purpose.
    What are you trying to achieve ?
    I want to start a program, terminate it after 3 seconds if it has not finished already,
    Thanks

  7. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Object::connect: No such signal QProces?????

    Do you need your program to be responsive while that three seconds is expiring?

  8. #7
    Join Date
    Nov 2009
    Posts
    59
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Object::connect: No such signal QProces?????

    Quote Originally Posted by ChrisW67 View Post
    Do you need your program to be responsive while that three seconds is expiring?
    yes
    Thanks

  9. #8
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Object::connect: No such signal QProces?????

    I want to start a program, terminate it after 3 seconds if it has not finished already,
    Should be simple - connect QProcess::started() signal to a 3 sec. timer's start() slot. Connect the timer's timeout() signal to your slot, where you will check if the process is finished - if not, kill it.
    Don't use QProcess::waitForFinished, because it will freeze your gui - you want to remain responsive.

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

    nthung (6th October 2011)

  11. #9
    Join Date
    Nov 2009
    Posts
    59
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Object::connect: No such signal QProces?????

    Quote Originally Posted by stampede View Post
    Should be simple - connect QProcess::started() signal to a 3 sec. timer's start() slot. Connect the timer's timeout() signal to your slot, where you will check if the process is finished - if not, kill it.
    Don't use QProcess::waitForFinished, because it will freeze your gui - you want to remain responsive.
    I will code as your guide
    But I wonder that how to know about a Process is timeout? because that it has no timeout function
    So I Coded as
    Qt Code:
    1. #ifndef QPROCESSTIMEOUT_H
    2. #define QPROCESSTIMEOUT_H
    3. #include<QProcess>
    4. #include<QDebug>
    5. #include<QTimer>
    6. class QProcessTimeout:public QObject
    7. {
    8. Q_OBJECT
    9. public:
    10. QProcessTimeout();
    11. void Timeout(int seconds){
    12. pr->start("C:\\Tesst.exe");
    13. emit TimeoutSignal(seconds);
    14. }
    15. signals:
    16. void TimeoutSignal(int seconds);
    17. public slots:
    18. void TimeOut(int x){
    19. if(pr->waitForFinished(x)==false){
    20. qDebug()<<"Time out";
    21. pr->kill();
    22. }
    23. else
    24. qDebug()<<"Sucessfully";
    25. }
    26. public:
    27. QTimer timer;
    28. };
    29.  
    30. #endif // QPROCESSTIMEOUT_H
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include "qprocesstimeout.h"
    2.  
    3. QProcessTimeout::QProcessTimeout()
    4. {
    5. pr=new QProcess();
    6. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include<qprocesstimeout.h>
    3. int main(int argc, char *argv[])
    4. {
    5. QCoreApplication a(argc, argv);
    6. QProcessTimeout x;
    7. QObject::connect(&x,SIGNAL(TimeoutSignal(int)),&x,SLOT(TimeOut(int)));
    8. x.Timeout(3999);
    9. return a.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    Thanks for supporting
    Last edited by nthung; 6th October 2011 at 11:19.

  12. #10
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Object::connect: No such signal QProces?????

    You want your program to be responsive during the time out period. You cannot use QProcess::waitForFinished() because it:
    Blocks until the process has finished and the finished() signal has been emitted, or until msecs milliseconds have passed.
    Here is a version of what Stampede suggested:
    Qt Code:
    1. #include <QtGui>
    2. #include <QDebug>
    3.  
    4. class Launcher: public QObject {
    5. Q_OBJECT
    6. static const int timeoutPeriod = 3000;
    7. QTimer m_timer;
    8. QProcess m_proc;
    9.  
    10. public:
    11. Launcher(QObject *p = 0): QObject(p) {
    12. // Set up the timer
    13. m_timer.setInterval( timeoutPeriod );
    14. m_timer.setSingleShot( true );
    15.  
    16. // These connections do the work
    17. connect(&m_proc, SIGNAL(started()), &m_timer, SLOT(start()));
    18. connect(&m_timer, SIGNAL(timeout()), this, SLOT(timedOut()));
    19.  
    20. // these are here only to illustrate what is being called
    21. connect(&m_proc, SIGNAL(started()), SLOT(processStarted()));
    22. connect(&m_proc, SIGNAL(finished(int,QProcess::ExitStatus)), SLOT(processFinished(int,QProcess::ExitStatus)));
    23. }
    24.  
    25. void launch() {
    26. static const QString cmd = "/bin/ls";
    27. static const QStringList args = QStringList() << "-lR" << "/";
    28.  
    29. // Start the process
    30. m_proc.start(cmd, args);
    31. }
    32.  
    33. public slots:
    34. void timedOut() {
    35. qDebug() << "Timed out";
    36. if (m_proc.state() != QProcess::NotRunning) {
    37. qDebug() << "Terminating";
    38. m_proc.terminate();
    39. }
    40. }
    41.  
    42. // these are here only to illustrate what is being called
    43. void processStarted() { qDebug() << "Process started"; }
    44. void processFinished(int exitCode, QProcess::ExitStatus exitStatus) { qDebug() << "Process Finished" << exitCode << exitStatus; }
    45. };
    46.  
    47. int main(int argc, char **argv)
    48. {
    49. QCoreApplication app(argc, argv);
    50. Launcher launcher;
    51. launcher.launch();
    52. return app.exec();
    53. }
    54. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    You could improve it by stopping the timer when the process finishes.
    Last edited by ChrisW67; 7th October 2011 at 00:10.

  13. The following user says thank you to ChrisW67 for this useful post:

    nthung (7th October 2011)

  14. #11
    Join Date
    Nov 2009
    Posts
    59
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Object::connect: No such signal QProces?????

    Quote Originally Posted by ChrisW67 View Post
    You want your program to be responsive during the time out period. You cannot use QProcess::waitForFinished() because it:

    Here is a version of what Stampede suggested:
    Qt Code:
    1. [COLOR="#FF0000"] connect(&m_proc, SIGNAL(started()), SLOT(processStarted()));[/COLOR]
    To copy to clipboard, switch view to plain text mode 
    You could improve it by stopping the timer when the process finishes.
    thanks so much for supporting.
    your code is esaly understandable.
    but the line code above lost a paramater, it is timer?
    Last edited by nthung; 7th October 2011 at 03:23.

  15. #12
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Object::connect: No such signal QProces?????

    No, it has not lost a parameter, and no it is not the timer: try it and see. Have a look at QObject::connect()... hint; there's more than one.

  16. The following user says thank you to ChrisW67 for this useful post:

    nthung (7th October 2011)

Similar Threads

  1. Connect signal/signal in Qt Designer
    By jlemaitre in forum Newbie
    Replies: 1
    Last Post: 22nd September 2010, 15:53
  2. Object::Connect problem
    By geleven in forum Qt Programming
    Replies: 3
    Last Post: 6th April 2010, 02:38
  3. Replies: 2
    Last Post: 20th September 2009, 02:52
  4. Connect signal from base to slot of sub-sub-object
    By donglebob in forum Qt Programming
    Replies: 15
    Last Post: 30th October 2008, 19:54
  5. Object::connect: Parentheses expected, slot...
    By bnilsson in forum Qt Programming
    Replies: 5
    Last Post: 5th April 2008, 15:02

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.