Hey,

I'm trying to compile a simple producer-consumer program with Qt, using QThreads. I get this error message when trying to compile:

In file included from /usr/include/qt4/QtCore/QThread:1,
from producer.h:4,
from mainwindow.cpp:3:
/usr/include/qt4/QtCore/qobject.h: In copy constructor ‘QThread::QThread(const QThread&)’:
/usr/include/qt4/QtCore/qobject.h:309: error: ‘QObject::QObject(const QObject&)’ is private
/usr/include/qt4/QtCore/qthread.h:60: error: within this context
In file included from mainwindow.cpp:3:
producer.h: In copy constructor ‘Producer::Producer(const Producer&)’:
producer.h:7: note: synthesized method ‘QThread::QThread(const QThread&)’ first required here
mainwindow.cpp: In member function ‘void MainWindow::on_btnStart_clicked()’:
mainwindow.cpp:31: note: synthesized method ‘Producer::Producer(const Producer&)’ first required here
make: *** [mainwindow.o] Virhe 1

I've tried to google this, but so far I haven't found anything related to this.

Here's my producer.h and producer.cpp:

#ifndef PRODUCER_H
#define PRODUCER_H

#include <QThread>
#include <QStack>

class Producer : public QThread {
    Q_OBJECT

    public:
        Producer(QStack<int> &s_par, int n_par);
        void run();
    private:
        int count;
        QStack<int> prod_stack;
};

#endif // PRODUCER_H
#include "producer.h"

Producer::Producer(QStack<int> &s_par, int n_par) : QThread() {
    count = n_par;
    prod_stack = s_par;
}

void Producer::run() {
    for(int i = 1; i <= count; i++) {
        prod_stack.push(i);
    }
}

I found http://www.qtcentre.org/archive/index.php/t-3604.html but I don't know if that gets you any further ahead than before. I had thought it might have had to do with your initializer list on the constructor on line 3 of the second listing.

Ah, you may be right. I thought I could just make a reference to the QStack, but I guess that's not possible. I'll try to remove the QStack reference and see what happens.

Actually, the problem wasn't about QStack. I tried to remove all the stuff involving QStack, but the problem still goes on. I'm helpless. :/

Please post the code for void MainWindow::on_btnStart_clicked() . It is around line 31 of mainwindow.cpp

From the error message, you are trying to copy an object of type Producer somewhere in that function and a copy constructor for Producer can not be synthesized (because the base class copy constructor is private).

Please post the code for void MainWindow::on_btnStart_clicked() . It is around line 31 of mainwindow.cpp

From the error message, you are trying to copy an object of type Producer somewhere in that function and a copy constructor for Producer can not be synthesized (because the base class copy constructor is private).

Ah, I figured it out now. I made a bit different approach to accomplish the same situation, and it now works. You were right, thanks for the advice :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.