PDA

View Full Version : QList/ QThread problem



Valheru
11th September 2006, 21:49
I'm trying to keep track of several objects by using a QList. The objects inherit from QThread and this is causing the compiler to choke. If I remove all QThread references from the class it compiles, but the moment I add the QThread specific stuff back in it dies :(


cd '/home/valheru/Projects/swat' && QTDIR="/usr" gmake -j1
cd src && gmake -f Makefile
compiling swat.cpp (g++)
/usr/include/qt4/QtCore/qobject.h: In copy constructor ‘QThread::QThread(const QThread&)’:
/usr/include/qt4/QtCore/qthread.h:40: instantiated from ‘void QList<T>::append(const T&) [with T = Connection]’
swat.cpp:143: instantiated from here
/usr/include/qt4/QtCore/qobject.h:271: error: ‘QObject::QObject(const QObject&)’ is private
/usr/include/qt4/QtCore/qthread.h:40: error: within this context
connection.h: In copy constructor ‘Connection::Connection(const Connection&)’:
connection.h:28: note: synthesized method ‘QThread::QThread(const QThread&)’ first required here
/usr/include/qt4/QtCore/qmutex.h:68: error: ‘QMutex::QMutex(const QMutex&)’ is private
connection.h:28: error: within this context
/usr/include/qt4/QtCore/qwaitcondition.h:52: error: ‘QWaitCondition::QWaitCondition(const QWaitCondition&)’ is private
connection.h:28: error: within this context
/usr/include/qt4/QtCore/qlist.h: In member function ‘void QList<T>::append(const T&) [with T = Connection]’:
/usr/include/qt4/QtCore/qlist.h:396: note: synthesized method ‘Connection::Connection(const Connection&)’ first required here
/usr/include/qt4/QtCore/qobject.h: In member function ‘QThread& QThread::operator=(const QThread&)’:
/usr/include/qt4/QtCore/qthread.h:40: instantiated from ‘void QList<T>::node_construct(QList<T>::Node*, const T&) [with T = Connection]’
/usr/include/qt4/QtCore/qlist.h:394: instantiated from ‘void QList<T>::append(const T&) [with T = Connection]’
swat.cpp:143: instantiated from here
/usr/include/qt4/QtCore/qobject.h:271: error: ‘QObject& QObject::operator=(const QObject&)’ is private
/usr/include/qt4/QtCore/qthread.h:40: error: within this context
connection.h: In member function ‘Connection& Connection::operator=(const Connection&)’:
connection.h:28: note: synthesized method ‘QThread& QThread::operator=(const QThread&)’ first required here
/usr/include/qt4/QtCore/qmutex.h:68: error: ‘QMutex& QMutex::operator=(const QMutex&)’ is private
connection.h:28: error: within this context
/usr/include/qt4/QtCore/qwaitcondition.h:52: error: ‘QWaitCondition& QWaitCondition::operator=(const QWaitCondition&)’ is private
connection.h:28: error: within this context
/usr/include/qt4/QtCore/qlist.h: In member function ‘void QList<T>::node_construct(QList<T>::Node*, const T&) [with T = Connection]’:
/usr/include/qt4/QtCore/qlist.h:309: note: synthesized method ‘Connecti
on& Connection::operator=(const Connection&)’ first required here
gmake[1]: *** [swat.o] Error 1
gmake: *** [sub-src-make_default] Error 2
*** Exited with status: 2 ***
The relevant code follows. As you can see, it's being added via a signal/slot, although I don't think taht that's the problem.


#ifndef CONNECTION_H
#define CONNECTION_H

#include <QtCore/QThread>
#include <QtCore/QMutex>
#include <QtCore/QWaitCondition>

class Connection : public QThread
{
Q_OBJECT
public:
Connection( const QString&, const quint16&, const QString&, const QString& );
~Connection();
void run();
private:
QString hostName, user, password;
quint16 port;
QMutex mutex;
QWaitCondition cond;
Q_SIGNALS:
void emitConnection( Connection* );
};

#endif //CONNECTION_H

#include "connection.h"

Connection::Connection( const QString &h, const quint16 &p, const QString &u, const QString &pass )
{
QMutexLocker locker( &mutex );
hostName = h;
port = p;
user = u;
password = pass;
}

Connection::~ Connection()
{
}

void Connection::run()
{
}

void SwatMw::connectionSlot( Connection *c )
{
connections->append( *c );
}

jacek
11th September 2006, 22:09
You can't copy QObject instances, so you should keep a list of pointers.

Valheru
12th September 2006, 11:22
That's what I was actually trying to do, but the .append() method kept on bitching that it wanted an object reference.
How can I declare the QList so that it is a list of pointers instead of objects?

jpn
12th September 2006, 11:48
How can I declare the QList so that it is a list of pointers instead of objects?


// declaration
QList<Connection*> connections;

// usage
void SwatMw::connectionSlot( Connection *c )
{
connections.append(c);
}

Valheru
12th September 2006, 13:58
Sweet, thanks :)