我一直在搞乱 Qt 和 C++ 一段时间,但我遇到了这个错误,似乎无法弄清楚它为什么会出现。const void* 转换错误消息已经回答了很多其他问题,但我真的看不出这些解释对我的情况有什么帮助,所以这里是:
我有一个 QList< MyType *const> 的重新实现“MyTypeManager”,因此是指向非 const MyTypes 的 const 指针列表。但是,当我重新实现一个函数时, addMyType 被调用
void MyTypeManager::addMyType(MyType *const var)
{
this->append(var);
}
发生以下错误:
In file included from /usr/include/qt4/QtCore/QList:1:0,
from ../qtsdlthread/mytypemanager.h:4,
from ../qtsdlthread/mytypemanager.cpp:1:
/usr/include/qt4/QtCore/qlist.h: In member function ‘void QList<T>::node_construct(QList<T>::Node*, const T&) [with T = MyType* const]’:
/usr/include/qt4/QtCore/qlist.h:499:13: instantiated from ‘void QList<T>::append(const T&) [with T = MyType* const]’
../qtsdlthread/mytypemanager.cpp:20:26: instantiated from here
/usr/include/qt4/QtCore/qlist.h:359:58: error: invalid conversion from ‘const void*’ to ‘void*’
/usr/include/qt4/QtCore/qlist.h: In member function ‘void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = MyType* const]’:
/usr/include/qt4/QtCore/qlist.h:666:9: instantiated from ‘QList<T>::Node* QList<T>::detach_helper_grow(int, int) [with T = MyType* const]’
/usr/include/qt4/QtCore/qlist.h:497:48: instantiated from ‘void QList<T>::append(const T&) [with T = MyType* const]’
../qtsdlthread/mytypemanager.cpp:20:26: instantiated from here
/usr/include/qt4/QtCore/qlist.h:386:17: error: invalid conversion from ‘const void*’ to ‘void*’
mytypemanager 中的 20:26 是上面发布的 this->append 行。