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