Abstract class problem
-
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 -
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?
-
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
-
As I said before, you need to reimplement run(). Not runn().
-
You're welcome :)
Please edit your original message and add "[SOLVED]" to the title, so that other people know that a solution exists.