こんにちはQVector
、QThread
オブジェクトを構築しようとしていますが、構築しようとするとこのエラーが発生します'QObject::QObject' : cannot access private member declared in class 'QObject'
。このエラーが発生する理由と、それを克服する方法、または回答の方向に向ける方法を誰かに教えてもらえますか。ありがとうございました。
メイン.CPP
#include <QCoreApplication>
#include "thread.h"
#include <QDebug>
#include <QThread>
main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
unsigned long long startingNumberAnswer = 0;
unsigned long long totalIterationsAnswer = 0;
int numberOfThreads = 10;
QVector<Thread> threads(numberOfThreads);
for(int l = 0; l < threads.size(); l++ ){
threads[l].setPriority(QThread::TimeCriticalPriority);
}
for(int i = 1; i< 2000000; i+=numberOfThreads){
qDebug() << "Longest iteration Number = " << startingNumberAnswer;
qDebug() << "Number of iterations for " << startingNumberAnswer << " is " << totalIterationsAnswer;
qDebug() << "Running # " << i;
system("CLS");
}
qDebug() << "Longest iteration Number = " << startingNumberAnswer;
qDebug() << "Number of iterations for " << startingNumberAnswer << " is " << totalIterationsAnswer;
return a.exec();
}
スレッド.H
#ifndef THREAD_H
#define THREAD_H
#include <QObject>
#include <QThread>
class Thread : public QThread
{
Q_OBJECT
public:
explicit Thread();
unsigned long long getloops();
unsigned long long getnumber();
signals:
public slots:
void run(unsigned long long value);
private:
unsigned long long largestNumber;
unsigned long long loops;
unsigned long long number;
};
#endif // THREAD_H
スレッド.CPP
#include "thread.h"
Thread::Thread()
{
}
void Thread::run(unsigned long long value)
{
unsigned long long n = value;
unsigned long long counter = 0;
while ( n > 1){
if(n%2 == 0){
n = n/2;
} else {
n = (3*n) + 1;
}
counter++;
}
loops = counter;
number = value;
}
unsigned long long Thread::getloops(){
return loops;
}
unsigned long long Thread::getnumber(){
return number;
}