PDA

View Full Version : ambiguous connect()



Cruz
27th August 2009, 11:17
Hello,

I don't quite know how to deal with this compiler error. I have a class that is a QWidget and a QThread at the same time. I'm using the thread to load a large file in the background. The progress bar on the widget should indicate how far the file is loaded. Here is the code:




Visualizer3D::Visualizer3D(QWidget *parent)
: QWidget(parent), QThread(parent)
{
ui.setupUi(this);

connect(this, SIGNAL(fileLoadingProgress(int)), ui.progressBar, SLOT(valueChanged(int))); // <-- this fails

start();
}

void Visualizer3D::run()
{
QFile file("data.dat");
file.open(QIODevice::ReadOnly);
QDataStream in(&file);
for (unsigned int i = 0; i < LINECOUNT; i++)
{
emit fileLoadingProgress((int)(100*i/LINECOUNT));
}
file.close();
}



And then it tells me:


visualizer3d.cpp:22: error: reference to ‘connect’ is ambiguous
../../qtsdk-2009.03/qt/include/QtCore/qobject.h:307: error: candidates are: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
../../qtsdk-2009.03/qt/include/QtCore/qobject.h:202: error: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
../../qtsdk-2009.03/qt/include/QtCore/qobject.h:307: error: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
../../qtsdk-2009.03/qt/include/QtCore/qobject.h:202: error: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)



Please help?

Cruz

Kumosan
27th August 2009, 11:26
QWidget inherits QObject and QThread inherits QObject so which QObject should the poor connect use? You cannot multiple inherit from more than one QObject class.

kwisp
27th August 2009, 11:35
Are you sure that you can write that:
QWidget(parent), QThread(parent) ???
There are 2 QObject object in this class.
I think its wrong.
:confused: