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. Abstract class problem
Forum Updated to NodeBB v4.3 + New Features

Abstract class problem

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 3.8k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    barun
    wrote on last edited by
    #1

    hello.please tell me. i m using qt 5.1.but when i m compiling..shows
    D:\program\asSer\myclient.cpp:33: ошибка: C2259: 'MyTask' : cannot instantiate abstract class
    due to following members:
    'void QRunnable::run(void)' : is abstract
    and my code is:
    MyTask *mytask = new MyTask();
    mytask->setAutoDelete(true);
    plz answer me

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

      QRunnable::run() is an "abstract function":http://www.programmerinterview.com/index.php/c-cplusplus/pure-virtual-function/ (also called a pure virtual function). You must override it when you inherit QRunnable -- that means you must create a MyTask::run() function.

      Can you show us your code for MyTask?

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • B Offline
        B Offline
        barun
        wrote on last edited by
        #3

        my code
        MyTask.cpp
        #include "mytask.h"

        MyTask::MyTask()
        {
        }
        void MyTask:: runn()
        {
        qDebug()<<"task started";
        int iNumber=0;
        for(int i=0;i<100;i++)
        {
        iNumber+=i;
        }
        qDebug()<<"task done";
        emit Result(iNumber);

        }
        mytask.h
        #ifndef MYTASK_H
        #define MYTASK_H

        #include <QRunnable>
        #include <QObject>
        #include <QDebug>

        class MyTask : public QObject,public QRunnable
        {
        Q_OBJECT
        public:
        MyTask();
        signals:
        void Result(int Number);
        protected:
        void runn();
        };

        #endif // MYTASK_H

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          As I said before, you need to reimplement run(). Not runn().

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • B Offline
            B Offline
            barun
            wrote on last edited by
            #5

            ok thank you..itz working..

            1 Reply Last reply
            0
            • JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              You're welcome :)

              Please edit your original message and add "[SOLVED]" to the title, so that other people know that a solution exists.

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              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