我在Qt的Q_MOC_OUTPUT_REVISION
。
基本上当我点击构建时,我会收到以下错误。我不完全确定这一切意味着什么,过去一小时我一直在努力想弄清楚它的含义但是我希望能更明智地解释错误的含义以及如何摆脱它们。< / p>
class Product: public QObject
{
Q_OBJECT
Q_PROPERTY(QString _productid READ _productid WRITE _productid)
Q_PROPERTY(QString _productcategoryid READ _productcategoryid WRITE _productcategoryid)
Q_PROPERTY(QString _name READ _name WRITE _name)
Q_PROPERTY(Productcontent * contents READ contents WRITE contents)//dynamic allocation of space for contents
Q_PROPERTY(QString _productimagepath READ _productimagepath WRITE _productimagepath)
Q_PROPERTY(QString _producticonpath READ _producticonpath WRITE _producticonpath )
Q_PROPERTY(QString _productPrice READ _productPrice WRITE _productPrice )
//since this does not change for each product, no need resending it each time
public:
static const string _xmldocpath;
static const string rootitemname;
static const string tagname;
QString _productid;
QString _name;
QString _productcategoryid;
QString _productimagepath;
QString _producticonpath;
QString _productPrice;
Product();
// const std::string &getfilepath();
// const std::string &getproducttagname();
// bool UpdateProductData(string id);
Q_INVOKABLE int FindProductByID(QString id);
~Product();
public slots:
signals:
};
以下错误结果。我不知道如何解决这个问题。任何帮助将不胜感激。
debug\moc_product.cpp: In member function 'virtual int Productcontent::qt_metacall(QMetaObject::Call, int, void**)':
debug\moc_product.cpp:77: error: no match for call to '(QString) ()'
debug\moc_product.cpp:78: error: no match for call to '(QString) ()'
debug\moc_product.cpp:84: error: no match for call to '(QString) (QString&)'
debug\moc_product.cpp:85: error: no match for call to '(QString) (QString&)'
debug\moc_product.cpp: In member function 'virtual int Product::qt_metacall(QMetaObject::Call, int, void**)':
debug\moc_product.cpp:179: error: no match for call to '(QString) ()'
debug\moc_product.cpp:180: error: no match for call to '(QString) ()'
debug\moc_product.cpp:181: error: no match for call to '(QString) ()'
debug\moc_product.cpp:182: error: 'contents' was not declared in this scope
debug\moc_product.cpp:183: error: no match for call to '(QString) ()'
debug\moc_product.cpp:184: error: no match for call to '(QString) ()'
debug\moc_product.cpp:185: error: no match for call to '(QString) ()'
debug\moc_product.cpp:191: error: no match for call to '(QString) (QString&)'
debug\moc_product.cpp:192: error: no match for call to '(QString) (QString&)'
debug\moc_product.cpp:193: error: no match for call to '(QString) (QString&)'
debug\moc_product.cpp:194: error: 'contents' was not declared in this scope
debug\moc_product.cpp:195: error: no match for call to '(QString) (QString&)'
debug\moc_product.cpp:196: error: no match for call to '(QString) (QString&)'
debug\moc_product.cpp:197: error: no match for call to '(QString) (QString&)'
mingw32-make.exe[1]: Leaving directory `C:/Users/minel/QMLUIProject_One-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug'
mingw32-make.exe[1]: *** [debug/moc_product.o] Error 1
mingw32-make.exe: *** [debug] Error 2
17:45:04: The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project QMLUIProject_One (target: Desktop)
When executing build step 'Make'
答案 0 :(得分:3)
在我看来,您现在还没有使用Q_PROPERTY。 这是基于您在_productid属性上的代码的示例,我没有包含不必要的内容:
class Product: public QObject
{
Q_OBJECT
Q_PROPERTY(QString _productid READ _getProductid WRITE _setProductid)
public:
QString _productid;
QString _getProductid() const {return _productid;}
void _setProductid(QString product){_productid = product;}
};
对于READ您设置函数名称返回_productid的值。
对于WRITE您可以设置_productid的功能设置值。
您在所有这些上设置了您的属性的名称,并且Qt宏Q_PROPERTY将它们设置为moc_file中的函数。编译器返回错误,因为他没有找到像QString Product :: _ productid()或void Product :: _ productid(QString)这样的函数。
宏Q_PROPERTY的详细信息和更多示例:http://developer.qt.nokia.com/doc/qt-4.8/properties.html