我有一些带有 Qt 4 函数的 C++ 代码:
QColorDialog colordialog0(&window0);
colordialog0.show();
QPixmap pixmap0(10, 10);
QObject::connect(&colordialog0, SIGNAL(colorSelected(const QColor &)), &pixmap0, SLOT(fill(const QColor &)));
当我构建一个项目时,它编译时出现错误:
error C2665: 'QObject::connect' : none of the 3 overloads could convert all the argument types
\qt\include\qtcore\../../src/corelib/kernel/qobject.h(204): could be 'bool QObject::connect(const QObject *,const char *,const QObject *,const char *,Qt::ConnectionType)'
\qt\include\qtcore\../../src/corelib/kernel/qobject.h(217): or 'bool QObject::connect(const QObject *,const QMetaMethod &,const QObject *,const QMetaMethod &,Qt::ConnectionType)'
\qt\include\qtcore\../../src/corelib/kernel/qobject.h(231): or 'bool QObject::connect(const QObject *,const char *,const char *,Qt::ConnectionType) const'
while trying to match the argument list '(QColorDialog *, const char *, QPixmap *, const char *)'
我无法理解这一点,因为当我编译另一个代码(没有 Q_OBJECT、moc 文件和其他)时:
QFileDialog filedialog0;
filedialog0.show();
QLabel label0(¢ralwidget0);
QObject::connect(&filedialog0, SIGNAL(fileSelected(const QString &)), &label0, SLOT(setText(const QString &)));
这不是错误。我知道原因在于函数重载。那么,如何只用一个函数编译(VS2008)?
谢谢。
PS对不起我的英语。