PDA

View Full Version : `QObject' is an ambiguous base of `ClientThread'



probine
7th December 2006, 12:51
I have this class


#include <QTcpSocket>
#include <QTextBrowser>
#include "clientthread.h"

ClientThread::ClientThread(int socketDescriptor)
{
_socketDescriptor = socketDescriptor;
textBrowser = new QTextBrowser(this);
setWindowTitle("Server version 0.9 beta");
setCentralWidget(textBrowser);
setFixedSize(400,400);
show();
run();

}


void ClientThread::run()
{
tcpSocket = new QTcpSocket();
if(!tcpSocket->setSocketDescriptor(_socketDescriptor))
textBrowser->append("Error in the connection");
else
textBrowser->append("Client successfully connected");
iniConnection();
exec();
}


void ClientThread::iniConnection()
{
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readData()));
}

void ClientThread::readData()
{

}


When i try to compile it, I get this error:

clientthread.cpp:33: error: `QObject' is an ambiguous base of `ClientThread'

I know the error can be disabled in this lines


void ClientThread::iniConnection()
{
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readData()));
}

The "connect" is the problem

What is wrong ?

jpn
7th December 2006, 13:17
Sounds like you are multi-inheriting QObject. That is not possible. Check for example this post (http://www.qtcentre.org/forum/p-multiinherit-trouble-template-qlist-post22235/postcount4.html).

By the way, modifying widgets outside the main GUI thread is a no no:

void ClientThread::run()
{
...
textBrowser->append("Error in the connection"); // !!
...
textBrowser->append("Client successfully connected"); // !!
...
}

It's documented here (http://doc.trolltech.com/4.2/threads.html#qobject-reentrancy):


Although QObject is reentrant, the GUI classes, notably QWidget and all its subclasses, are not reentrant. They can only be used from the main thread.


Use signals and slots (queued connection) or custom events to cross the thread boundaries.