Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. error C2440: 'static_cast': cannot convert from 'const QObject *' to 'T'
Forum Updated to NodeBB v4.3 + New Features

error C2440: 'static_cast': cannot convert from 'const QObject *' to 'T'

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pradson
    wrote on last edited by
    #1

    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,

    jsulmJ 1 Reply Last reply
    0
    • P Pradson

      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,

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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 *".

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      P 1 Reply Last reply
      1
      • jsulmJ jsulm

        @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 *".

        P Offline
        P Offline
        Pradson
        wrote on last edited by
        #3

        @jsulm

        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,

        jsulmJ 1 Reply Last reply
        0
        • P Pradson

          @jsulm

          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,

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          P 1 Reply Last reply
          1
          • jsulmJ jsulm

            @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

            P Offline
            P Offline
            Pradson
            wrote on last edited by
            #5

            @jsulm

            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,

            jsulmJ 1 Reply Last reply
            0
            • P Pradson

              @jsulm

              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,

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Pradson Did you also include the header file (#include <QOpenGLWidget>)?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              P 1 Reply Last reply
              2
              • jsulmJ jsulm

                @Pradson Did you also include the header file (#include <QOpenGLWidget>)?

                P Offline
                P Offline
                Pradson
                wrote on last edited by
                #7

                @jsulm

                Thanks a lot for your kind support.

                Now, the compilation errors have been gone.

                Thanks,

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved