Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9224989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:28:00+00:00 2026-06-18T04:28:00+00:00

Hello I’m trying to build a QVector of QThread objects but when I try

  • 0

Hello I’m trying to build a QVector of QThread objects but when I try to build I get this error 'QObject::QObject' : cannot access private member declared in class 'QObject'. Can someone tell me why I am getting this error and how to over come it or point me in the direction of answer. Thank you for you time.

MAIN.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();
}

THREAD.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

THREAD.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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:28:01+00:00Added an answer on June 18, 2026 at 4:28 am

    Simply, QObject objects are not copyable nor assignable – check the official documentation:

    No copy constructor or assignment operator

    QObject has neither a copy constructor nor an assignment operator.
    This is by design. Actually, they are declared, but in a private
    section with the macro Q_DISABLE_COPY(). In fact, all Qt classes
    derived from QObject (direct or indirect) use this macro to declare
    their copy constructor and assignment operator to be private. The
    reasoning is found in the discussion on Identity vs Value on the Qt
    Object Model page.

    The main consequence is that you should use pointers to QObject (or to
    your QObject subclass) where you might otherwise be tempted to use
    your QObject subclass as a value. For example, without a copy
    constructor, you can’t use a subclass of QObject as the value to be
    stored in one of the container classes. You must store pointers.

    So, you will need to use QVector<Thread*> to store threads (don’t forget to create objects before using them).

    It is also noted in QVector’s documentation:

    QVector’s value type must be an assignable data type. This covers most data types that are commonly used, but the compiler won’t let you, for example, store a QWidget as a value; instead, store a QWidget *. A few functions have additional requirements; for example, indexOf() and lastIndexOf() expect the value type to support operator==(). These requirements are documented on a per-function basis.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have like this 2 tables class User public int UserId{get;set;} { ....
Hello I've got this query to get users by email, which is an unique
Hello I am using this code to get the data I need from 5
Hello guys, I have an error I cannot solve, on a ASP.NET website. One
Hello again stackoverflow! So i build this script: <?php $xmlurl = 'http://api.ipinfodb.com/v2/ip_query.php?key=apikey&ip=127.0.0.100&timezone=false'; $xml =
Hello I'm trying to add MapView to LinearLayout this is my code: GoogleMap mMap
Hello! I've been programming for a long time but just started developing for android,
hello evrey body i have try really hard to write a file to android
Hello my rendering is very glitchy on Tegra 3 devices.. any Idea how this
Hello everyone and thanks for your help! I currently have this program that renames

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.