Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. error: cannot allocate an object of abstract type 'ClassName'
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved General and Desktop
threadthreadingsocket
4 Posts 3 Posters 6.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • GiorgiG Offline
    GiorgiG Offline
    Giorgi
    wrote on last edited by Giorgi
    #1

    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:

    main.cpp

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

    testrunnable.h

    #ifndef TESTRUNNABLE_H
    #define TESTRUNNABLE_H
    
    #include <QRunnable>
    
    class TestRunnable : public QRunnable
    {
    public:
        TestRunnable();
    };
    
    #endif // TESTRUNNABLE_H
    

    testrunnable.cpp

    #include "testrunnable.h"
    
    TestRunnable::TestRunnable()
    {
    }
    
    
    1 Reply Last reply
    0
    • G Offline
      G Offline
      GrahamL
      wrote on last edited by
      #2

      Hi
      You need to override the abstract 'run' method

      1 Reply Last reply
      1
      • JeroentjehomeJ Offline
        JeroentjehomeJ Offline
        Jeroentjehome
        wrote on last edited by
        #3

        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.

        Greetz, Jeroen

        1 Reply Last reply
        1
        • GiorgiG Offline
          GiorgiG Offline
          Giorgi
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved