Я новичок в QPointers и модифицирую старый код, который работал с обычными указателями. В моем заголовочном файле я определяю QPointer следующим образом:
error: invalid ‘static_cast’ from type ‘QThread*’ to type ‘QPointer::QObjectType*’ {aka ‘QObject*’}
/opt/Qt/5.15.2/gcc_64/include/QtCore/qpointer.h: In instantiation of ‘QPointer& QPointer::operator=(T*) [with T = QThread]’:
../globals.cpp:128:26: required from here
/opt/Qt/5.15.2/gcc_64/include/QtCore/qpointer.h:74:17: error: invalid ‘static_cast’ from type ‘QThread*’ to type ‘QPointer::QObjectType*’ {aka ‘QObject*’}
74 | { wp.assign(static_cast(p)); return *this; }
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: invalid ‘static_cast’ from type ‘QObject*’ to type ‘QThread*’
In file included from /opt/Qt/5.15.2/gcc_64/include/QtCore/QPointer:1,
from ../../haast-call-recovery-control/src/cpp/globals.h:18,
from ../../haast-call-recovery-control/src/cpp/globals.cpp:4:
/opt/Qt/5.15.2/gcc_64/include/QtCore/qpointer.h: In instantiation of ‘T* QPointer::data() const [with T = QThread]’:
/opt/Qt/5.15.2/gcc_64/include/QtCore/qpointer.h:83:14: required from ‘QPointer::operator T*() const [with T = QThread]’
../globals.cpp:135:20: required from here
/opt/Qt/5.15.2/gcc_64/include/QtCore/qpointer.h:77:14: error: invalid ‘static_cast’ from type ‘QObject*’ to type ‘QThread*’
77 | { return static_cast(wp.internalData()); }
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Я подтвердил, что QThread происходит от QObject. Что не так с этим типом заданий?
Я новичок в QPointers и модифицирую старый код, который работал с обычными указателями. В моем заголовочном файле я определяю QPointer следующим образом: [code]QPointer m_qthreadclass; [/code] и я определяю методы получения и установки следующим образом: [code]void SomeClass::mythread(QThread *tc) { m_qthreadclass = tc; // Error 1 }
QThread *SomeClass::mythread() { QThread * tc = m_qthreadclass; // Error 2 return tc; } [/code] Ошибка 1: [code]error: invalid ‘static_cast’ from type ‘QThread*’ to type ‘QPointer::QObjectType*’ {aka ‘QObject*’} /opt/Qt/5.15.2/gcc_64/include/QtCore/qpointer.h: In instantiation of ‘QPointer& QPointer::operator=(T*) [with T = QThread]’: ../globals.cpp:128:26: required from here /opt/Qt/5.15.2/gcc_64/include/QtCore/qpointer.h:74:17: error: invalid ‘static_cast’ from type ‘QThread*’ to type ‘QPointer::QObjectType*’ {aka ‘QObject*’} 74 | { wp.assign(static_cast(p)); return *this; } | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ [/code] Ошибка 2: [code]error: invalid ‘static_cast’ from type ‘QObject*’ to type ‘QThread*’ In file included from /opt/Qt/5.15.2/gcc_64/include/QtCore/QPointer:1, from ../../haast-call-recovery-control/src/cpp/globals.h:18, from ../../haast-call-recovery-control/src/cpp/globals.cpp:4: /opt/Qt/5.15.2/gcc_64/include/QtCore/qpointer.h: In instantiation of ‘T* QPointer::data() const [with T = QThread]’: /opt/Qt/5.15.2/gcc_64/include/QtCore/qpointer.h:83:14: required from ‘QPointer::operator T*() const [with T = QThread]’ ../globals.cpp:135:20: required from here /opt/Qt/5.15.2/gcc_64/include/QtCore/qpointer.h:77:14: error: invalid ‘static_cast’ from type ‘QObject*’ to type ‘QThread*’ 77 | { return static_cast(wp.internalData()); } | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [/code] Я подтвердил, что QThread происходит от QObject. Что не так с этим типом заданий?