error: cannot allocate an object of abstract type 'ClassName'

  • Hi everyone.

    I saw QRunnable examples and I want to test it, but I have an error:
    error: cannot allocate an object of abstract type 'TestRunnable'

    Why my class TestRunnable which extends QRunnable is abstract?

    Here is sample code:


    #include <QCoreApplication>
    #include "testrunnable.h"
    int main(int argc, char *argv[])
        QCoreApplication a(argc, argv);
        TestRunnable *task = new TestRunnable();
        return a.exec();


    #ifndef TESTRUNNABLE_H
    #define TESTRUNNABLE_H
    #include <QRunnable>
    class TestRunnable : public QRunnable
    #endif // TESTRUNNABLE_H


    #include "testrunnable.h"

  • Hi
    You need to override the abstract 'run' method

  • The name 'abstract' tells the problem. Abstract classes only declare functions that need to be implemented/overwritten before you are able to allocate and use them. So read the QRunnable header file and check out all the virtual functions and overwrite them.

  • OH yes. thread without run...
    thank you.