Qt 4.6和4.7之间的QString类的变化

时间:2011-04-13 13:38:19

标签: c++ constructor qt4 overloading

我现在正在尝试用Qt 4.7编译sqlitebrowser,在编译运行期间我得到了他的错误:

g++ -c -pipe -O2 -Wall -W -DQT_NO_DEBUG -DQT_QT3SUPPORT_LIB -DQT3_SUPPORT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/share/qt4/mkspecs/freebsd-g++ -I. -I/usr/local/include/qt4/QtCore -I/usr/local/include/qt4/QtGui -I/usr/local/include/qt4/Qt3Support -I/usr/local/include/qt4 -Isqlite_source -I.moc -I/usr/local/include -o .obj/extendedmainform.o extendedmainform.cpp
In file included from findform.h:24,
                 from form1.h:31,
                 from extendedmainform.h:4,
                 from extendedmainform.cpp:1:
sqlitedb.h: In constructor 'DBBrowserField::DBBrowserField()':
sqlitedb.h:44: error: call of overloaded 'QString(int)' is ambiguous
/usr/local/include/qt4/QtCore/qstring.h:428: note: candidates are: QString::QString(const QByteArray&)
/usr/local/include/qt4/QtCore/qstring.h:426: note:                 QString::QString(const char*)
/usr/local/include/qt4/QtCore/qstring.h:728: note:                 QString::QString(const QString&)
/usr/local/include/qt4/QtCore/qstring.h:106: note:                 QString::QString(QChar)
/usr/local/include/qt4/QtCore/qstring.h:105: note:                 QString::QString(const QChar*)
sqlitedb.h: In constructor 'DBBrowserIndex::DBBrowserIndex()':
sqlitedb.h:58: error: call of overloaded 'QString(int)' is ambiguous
/usr/local/include/qt4/QtCore/qstring.h:428: note: candidates are: QString::QString(const QByteArray&)
/usr/local/include/qt4/QtCore/qstring.h:426: note:                 QString::QString(const char*)
/usr/local/include/qt4/QtCore/qstring.h:728: note:                 QString::QString(const QString&)
/usr/local/include/qt4/QtCore/qstring.h:106: note:                 QString::QString(QChar)
/usr/local/include/qt4/QtCore/qstring.h:105: note:                 QString::QString(const QChar*)
sqlitedb.h: In constructor 'DBBrowserTable::DBBrowserTable()':
sqlitedb.h:73: error: call of overloaded 'QString(int)' is ambiguous
/usr/local/include/qt4/QtCore/qstring.h:428: note: candidates are: QString::QString(const QByteArray&)
/usr/local/include/qt4/QtCore/qstring.h:426: note:                 QString::QString(const char*)
/usr/local/include/qt4/QtCore/qstring.h:728: note:                 QString::QString(const QString&)
/usr/local/include/qt4/QtCore/qstring.h:106: note:                 QString::QString(QChar)
/usr/local/include/qt4/QtCore/qstring.h:105: note:                 QString::QString(const QChar*)
*** Error code 1

我检查了Qt文档(4.6和4.7)以查看Qstring构造函数中的任何更改,但我只看到一个新的one overload,所以我的问题是我需要在sqlitebrowser中更改以便编译它。< / p>

2 个答案:

答案 0 :(得分:4)

根据QString in Qt 4.6,只有one candidate可以将指针作为参数。但是Qt 4.7中有两个QString构造函数可以将指针作为参数。我认为这引起了编译错误。

您可以强制它的行为类似于Qt 4.6,如下所示:

name((const char*) 0)

答案 1 :(得分:0)

无论你用int创建一个QString - 你需要告诉Qt你的意思是什么

如果它是一个实际的文字数字,你要转换为一个字符串使用QString(“%u”)。arg()函数