Model_Test 对于 Qt 5?

Model_Test for Qt 5?

在过去 (Qt 4.8),我使用 modeltest class 来测试 QAbstractItemModel 实现。然而,Qt 5 似乎已经破坏了兼容性,因为在尝试开箱即用地编译它时会爆发大量错误,包括对不再是 QAbstractItemModel 成员的函数 reset() 的调用。

是否有人知道更新的存储库,或者是否有人自行修复了 modeltest?我专门使用 Qt 5.3.1.

错误:

C:\Documents\Visual Studio 2013\Projects\modeltest\dynamictreemodel.cpp(306): error C2039: 'reset' : is not a member of 'DynamicTreeModel'
1>          c:\documents\visual studio 2013\projects\modeltest\dynamictreemodel.h(51) : see declaration of 'DynamicTreeModel'
1>  modeltest.cpp
1>C:\Documents\Visual Studio 2013\Projects\modeltest\modeltest.cpp(419): error C2065: 'qVariantCanConvert' : undeclared identifier
1>C:\Documents\Visual Studio 2013\Projects\modeltest\modeltest.cpp(419): error C2275: 'QString' : illegal use of this type as an expression
1>          C:\Qt\qt-5.3.1-x64-msvc2010-opengl\qt-5.3.1-x64-msvc2010-opengl\include\QtCore/qstring.h(213) : see declaration of 'QString'
1>C:\Documents\Visual Studio 2013\Projects\modeltest\modeltest.cpp(423): error C2065: 'qVariantCanConvert' : undeclared identifier
1>C:\Documents\Visual Studio 2013\Projects\modeltest\modeltest.cpp(423): error C2275: 'QString' : illegal use of this type as an expression
1>          C:\Qt\qt-5.3.1-x64-msvc2010-opengl\qt-5.3.1-x64-msvc2010-opengl\include\QtCore/qstring.h(213) : see declaration of 'QString'
1>C:\Documents\Visual Studio 2013\Projects\modeltest\modeltest.cpp(427): error C2065: 'qVariantCanConvert' : undeclared identifier
1>C:\Documents\Visual Studio 2013\Projects\modeltest\modeltest.cpp(427): error C2275: 'QString' : illegal use of this type as an expression
1>          C:\Qt\qt-5.3.1-x64-msvc2010-opengl\qt-5.3.1-x64-msvc2010-opengl\include\QtCore/qstring.h(213) : see declaration of 'QString'
1>C:\Documents\Visual Studio 2013\Projects\modeltest\modeltest.cpp(433): error C2065: 'qVariantCanConvert' : undeclared identifier
1>C:\Documents\Visual Studio 2013\Projects\modeltest\modeltest.cpp(433): error C2275: 'QSize' : illegal use of this type as an expression
1>          C:\Qt\qt-5.3.1-x64-msvc2010-opengl\qt-5.3.1-x64-msvc2010-opengl\include\QtCore/qsize.h(51) : see declaration of 'QSize'
1>C:\Documents\Visual Studio 2013\Projects\modeltest\modeltest.cpp(439): error C2065: 'qVariantCanConvert' : undeclared identifier
1>C:\Documents\Visual Studio 2013\Projects\modeltest\modeltest.cpp(439): error C2275: 'QFont' : illegal use of this type as an expression
1>          C:\Qt\qt-5.3.1-x64-msvc2010-opengl\qt-5.3.1-x64-msvc2010-opengl\include\QtGui/qfont.h(58) : see declaration of 'QFont'
1>C:\Documents\Visual Studio 2013\Projects\modeltest\modeltest.cpp(452): error C2065: 'qVariantCanConvert' : undeclared identifier
1>C:\Documents\Visual Studio 2013\Projects\modeltest\modeltest.cpp(452): error C2275: 'QColor' : illegal use of this type as an expression
1>          C:\Qt\qt-5.3.1-x64-msvc2010-opengl\qt-5.3.1-x64-msvc2010-opengl\include\QtGui/qcolor.h(65) : see declaration of 'QColor'
1>C:\Documents\Visual Studio 2013\Projects\modeltest\modeltest.cpp(457): error C2065: 'qVariantCanConvert' : undeclared identifier
1>C:\Documents\Visual Studio 2013\Projects\modeltest\modeltest.cpp(457): error C2275: 'QColor' : illegal use of this type as an expression
1>          C:\Qt\qt-5.3.1-x64-msvc2010-opengl\qt-5.3.1-x64-msvc2010-opengl\include\QtGui/qcolor.h(65) : see declaration of 'QColor'
1>  tst_modeltest.cpp
1>C:\Documents\Visual Studio 2013\Projects\modeltest\tst_modeltest.cpp(114): error C2065: 'QTreeWidget' : undeclared identifier
1>C:\Documents\Visual Studio 2013\Projects\modeltest\tst_modeltest.cpp(114): error C2146: syntax error : missing ';' before identifier 'widget'
1>C:\Documents\Visual Studio 2013\Projects\modeltest\tst_modeltest.cpp(114): error C2065: 'widget' : undeclared identifier
1>C:\Documents\Visual Studio 2013\Projects\modeltest\tst_modeltest.cpp(116): error C2065: 'widget' : undeclared identifier
1>C:\Documents\Visual Studio 2013\Projects\modeltest\tst_modeltest.cpp(116): error C2228: left of '.model' must have class/struct/union
1>          type is 'unknown-type'
1>C:\Documents\Visual Studio 2013\Projects\modeltest\tst_modeltest.cpp(116): error C2512: 'ModelTest' : no appropriate default constructor available
1>C:\Documents\Visual Studio 2013\Projects\modeltest\tst_modeltest.cpp(118): error C2065: 'QTreeWidgetItem' : undeclared identifier
1>C:\Documents\Visual Studio 2013\Projects\modeltest\tst_modeltest.cpp(118): error C2065: 'root' : undeclared identifier
1>C:\Documents\Visual Studio 2013\Projects\modeltest\tst_modeltest.cpp(118): error C2061: syntax error : identifier 'QTreeWidgetItem'
1>C:\Documents\Visual Studio 2013\Projects\modeltest\tst_modeltest.cpp(120): error C2061: syntax error : identifier 'QTreeWidgetItem'
1>C:\Documents\Visual Studio 2013\Projects\modeltest\tst_modeltest.cpp(122): error C2065: 'QTreeWidgetItem' : undeclared identifier
1>C:\Documents\Visual Studio 2013\Projects\modeltest\tst_modeltest.cpp(122): error C2065: 'root' : undeclared identifier
1>C:\Documents\Visual Studio 2013\Projects\modeltest\tst_modeltest.cpp(122): error C2227: left of '->child' must point to class/struct/union/generic type
1>          type is 'unknown-type'
1>C:\Documents\Visual Studio 2013\Projects\modeltest\tst_modeltest.cpp(123): error C2065: 'root' : undeclared identifier
1>C:\Documents\Visual Studio 2013\Projects\modeltest\tst_modeltest.cpp(123): error C2227: left of '->removeChild' must point to class/struct/union/generic type
1>          type is 'unknown-type'
1>C:\Documents\Visual Studio 2013\Projects\modeltest\tst_modeltest.cpp(124): error C2065: 'QTreeWidgetItem' : undeclared identifier
1>C:\Documents\Visual Studio 2013\Projects\modeltest\tst_modeltest.cpp(124): error C3867: 'QObject::parent': function call missing argument list; use '&QObject::parent' to create a pointer to member
1>C:\Documents\Visual Studio 2013\Projects\modeltest\tst_modeltest.cpp(124): error C2061: syntax error : identifier 'QTreeWidgetItem'
1>C:\Documents\Visual Studio 2013\Projects\modeltest\tst_modeltest.cpp(126): error C2065: 'widget' : undeclared identifier
1>C:\Documents\Visual Studio 2013\Projects\modeltest\tst_modeltest.cpp(126): error C2228: left of '.setItemHidden' must have class/struct/union
1>          type is 'unknown-type'
1>C:\Documents\Visual Studio 2013\Projects\modeltest\tst_modeltest.cpp(126): error C3867: 'QObject::parent': function call missing argument list; use '&QObject::parent' to create a pointer to member
1>C:\Documents\Visual Studio 2013\Projects\modeltest\tst_modeltest.cpp(128): error C2065: 'widget' : undeclared identifier
1>C:\Documents\Visual Studio 2013\Projects\modeltest\tst_modeltest.cpp(128): error C2228: left of '.sortByColumn' must have class/struct/union

看来这可以通过几个简单的步骤解决:

  1. reset() 错误正在测试一个已弃用的函数,可以将其注释掉。
  2. qVariantCanConvert 错误可以按照建议 here on transitioning from Qt 4.8 to Qt 5
  3. 修复
  4. 其余的错误可以通过确保包含所有适当的 headers 来解决。