error C2440: 'static_cast': cannot convert from 'const QObject *' to 'T'
-
wrote on 28 Aug 2023, 06:06 last edited by
Hi,
I am facing the below mentioned compilation error when I am porting my Qt5 application to Qt6. Kindly suggest the solution-
------------Compilation Error------------
C:\Qt\Qt6.4.0\6.4.0\msvc2019_64\include\QtCore\qobject.h(455): error C2440: 'static_cast': cannot convert from 'const QObject *' to 'T'
with
[
T=QDesignerCustomWidgetInterface *
]
C:\Qt\Qt6.4.0\6.4.0\msvc2019_64\include\QtCore\qobject.h(455): note: Conversion loses qualifiers
sharedFiles\pluginwidgetmanager.cpp(545): note: see reference to function template instantiation 'T qobject_cast<QDesignerCustomWidgetInterface>(const QObject *)' being compiled
with
[
T=QDesignerCustomWidgetInterface *
]Thanks,
-
Hi,
I am facing the below mentioned compilation error when I am porting my Qt5 application to Qt6. Kindly suggest the solution-
------------Compilation Error------------
C:\Qt\Qt6.4.0\6.4.0\msvc2019_64\include\QtCore\qobject.h(455): error C2440: 'static_cast': cannot convert from 'const QObject *' to 'T'
with
[
T=QDesignerCustomWidgetInterface *
]
C:\Qt\Qt6.4.0\6.4.0\msvc2019_64\include\QtCore\qobject.h(455): note: Conversion loses qualifiers
sharedFiles\pluginwidgetmanager.cpp(545): note: see reference to function template instantiation 'T qobject_cast<QDesignerCustomWidgetInterface>(const QObject *)' being compiled
with
[
T=QDesignerCustomWidgetInterface *
]Thanks,
@Pradson You're trying to cast a const object to a non-const object. Either cast from const to const or change "const QObject *" to "QObject *" depending on your needs. Or cast to "const QDesignerCustomWidgetInterface *".
-
@Pradson You're trying to cast a const object to a non-const object. Either cast from const to const or change "const QObject *" to "QObject *" depending on your needs. Or cast to "const QDesignerCustomWidgetInterface *".
wrote on 28 Aug 2023, 07:50 last edited byThanks a lot.
Now, I am getting the below mentioned another compilation error when porting from Qt5 to Qt6-
---------- Compilation Error -----------
widgets.table(113): error C2027: use of undefined type 'QOpenGLWidget'Kindly suggest the solution.
Thanks,
-
Thanks a lot.
Now, I am getting the below mentioned another compilation error when porting from Qt5 to Qt6-
---------- Compilation Error -----------
widgets.table(113): error C2027: use of undefined type 'QOpenGLWidget'Kindly suggest the solution.
Thanks,
@Pradson said in error C2440: 'static_cast': cannot convert from 'const QObject *' to 'T':
Kindly suggest the solution
Documentation already does: https://doc.qt.io/qt-6/qopenglwidget.html
Do you have this line in your pro file:QT += openglwidgets
Or, in case you're using CMake:
find_package(Qt6 REQUIRED COMPONENTS OpenGLWidgets) target_link_libraries(mytarget PRIVATE Qt6::OpenGLWidgets)
in CMakeLists.txt
-
@Pradson said in error C2440: 'static_cast': cannot convert from 'const QObject *' to 'T':
Kindly suggest the solution
Documentation already does: https://doc.qt.io/qt-6/qopenglwidget.html
Do you have this line in your pro file:QT += openglwidgets
Or, in case you're using CMake:
find_package(Qt6 REQUIRED COMPONENTS OpenGLWidgets) target_link_libraries(mytarget PRIVATE Qt6::OpenGLWidgets)
in CMakeLists.txt
wrote on 28 Aug 2023, 08:51 last edited byHi,
I have already added the the above suggestion (QT += openglwidgets) in my .pro file. Still, I am getting the same error as mentioned below-
------------ Compilation Error-------------
..\lib\myuilib\widgets.table(113): error C2027: use of undefined type 'QOpenGLWidget'
C:\Qt\Qt6.4.0\6.4.0\msvc2019_64\include\QtGui/qpixmap.h(137): note: see declaration of 'QOpenGLWidget'Thanks,
-
Hi,
I have already added the the above suggestion (QT += openglwidgets) in my .pro file. Still, I am getting the same error as mentioned below-
------------ Compilation Error-------------
..\lib\myuilib\widgets.table(113): error C2027: use of undefined type 'QOpenGLWidget'
C:\Qt\Qt6.4.0\6.4.0\msvc2019_64\include\QtGui/qpixmap.h(137): note: see declaration of 'QOpenGLWidget'Thanks,
@Pradson Did you also include the header file (#include <QOpenGLWidget>)?
1/7