Results 1 to 3 of 3

Thread: No such slot QCoreApplication ...

  1. #1
    Join Date
    Jan 2006
    Posts
    8
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default No such slot QCoreApplication ...

    I am trying to subclass QCoreApplication to execute various tasks that I define as part of a task class. The tasks have a "progress()" signal which I want to forward to the application, which can then report progress on its task to the console. I have the following code in MyConsoleApp.h

    Qt Code:
    1. class MyConsoleApp: public QCoreApplication
    2. {
    3. Q_OBJECT
    4. public:
    5. MyConsoleApp(int &argc, char **argv);
    6. void setTask(MyTask *my_task,
    7. bool exit_on_completion = true,
    8. bool show_progress=false);
    9. void executeTask();
    10. public slots:
    11. void showProgress(int i);
    12. private:
    13. MyTask* m_task;
    14. };
    To copy to clipboard, switch view to plain text mode 

    And in MyConsoleApp.cpp (MyTask is a subclass of QRunnable, it emits finished() when done and a progress(int) signal during processing):

    Qt Code:
    1. void MyConsoleApp::setTask(MyTask *my_task, bool exit_on_completion, bool show_progress) {
    2. m_task = my_task;
    3.  
    4. if(m_task && exit_on_completion) {
    5. QObject::connect(m_task, SIGNAL(finished()),
    6. this, SLOT( quit() ));
    7. }
    8. if(m_task && progress) {
    9. QObject::connect( m_task, SIGNAL(progress(int)),
    10. this, SLOT(showProgress(int)));
    11. }
    12.  
    13. }
    14.  
    15. void MyConsoleApp::executeTask() {
    16. if(m_task) {
    17. QThreadPool::globalInstance()->start(m_task);
    18. }
    19.  
    20. void MyConsoleApp::showProgress(int i) {
    21. std::cout << i << "% complete." << std::endl;
    22. }
    To copy to clipboard, switch view to plain text mode 

    Then my main function is:

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. MyConsoleApp a(argc, argv);
    4.  
    5. a.setTask( new MyTask(), true, true);
    6. a.executeTask();
    7.  
    8. return a.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 


    Sorry, this is not a compilable example. I tried to reduce it to one, and ended up with an even more strange error.

    Anyway, everything seems to work. My task is executed and runs to completion, and the application exits when the task is done. However, the progress is never displayed and I get the following error message when I run the program:

    QObject::connect: No such slot QCoreApplication::showProgress(int) in MyApp.cpp

    Which I cannot understand because the slot is there and they are connected. It seems like it is looking for a SLOT showProgress in the superclass (QCoreApplication) rather in the class which I have defined MyConsoleApp - and I am not sure why that happens.

    Any help would be appreciated.

    Regards,
    Craig

  2. #2
    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: No such slot QCoreApplication ...

    The file containing your MyConsoleApp declaration is listed in the PRO file HEADERS and qmake has been run since it was added?

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

    CraigD (9th July 2013)

  4. #3
    Join Date
    Jan 2006
    Posts
    8
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: No such slot QCoreApplication ...

    Quote Originally Posted by ChrisW67 View Post
    The file containing your MyConsoleApp declaration is listed in the PRO file HEADERS and qmake has been run since it was added?
    That must have been the problem. I created the program in QtCreator and when I checked the .pro file everything was there. However I tried restarting Creator and did a full rebuild
    and that fixed whatever the problem was. I guess the .pro file and Makefile got out of sync perhaps.

    That is one of the disadvantages of using a IDE I guess. I can save you work at times, but it also hides details about the build process, making them easy to forget.

    Thanks for your help.

    Craig

Similar Threads

  1. QCoreApplication... In a library.
    By hickscorp in forum Qt Programming
    Replies: 5
    Last Post: 23rd January 2010, 17:29
  2. QCoreApplication
    By Morea in forum Qt Programming
    Replies: 5
    Last Post: 4th June 2007, 20:58
  3. Use of QCoreApplication
    By moowy in forum Qt Programming
    Replies: 8
    Last Post: 18th May 2007, 09:33
  4. QCoreApplication!!!!
    By fellobo in forum Qt Programming
    Replies: 6
    Last Post: 17th January 2007, 01:56
  5. QCoreApplication And QSqlDatabase
    By ball in forum Qt Programming
    Replies: 1
    Last Post: 24th May 2006, 08:58

Tags for this Thread

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.