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 28 Aug 2023, 06:06 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,

    J 1 Reply Last reply 28 Aug 2023, 06:34
    0
    • P Pradson
      28 Aug 2023, 06:06

      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,

      J Online
      J Online
      jsulm
      Lifetime Qt Champion
      wrote on 28 Aug 2023, 06:34 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 28 Aug 2023, 07:50
      1
      • J jsulm
        28 Aug 2023, 06:34

        @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 28 Aug 2023, 07:50 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,

        J 1 Reply Last reply 28 Aug 2023, 07:52
        0
        • P Pradson
          28 Aug 2023, 07:50

          @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,

          J Online
          J Online
          jsulm
          Lifetime Qt Champion
          wrote on 28 Aug 2023, 07:52 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 28 Aug 2023, 08:51
          1
          • J jsulm
            28 Aug 2023, 07:52

            @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 28 Aug 2023, 08:51 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,

            J 1 Reply Last reply 28 Aug 2023, 08:58
            0
            • P Pradson
              28 Aug 2023, 08:51

              @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,

              J Online
              J Online
              jsulm
              Lifetime Qt Champion
              wrote on 28 Aug 2023, 08:58 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 28 Aug 2023, 11:12
              2
              • J jsulm
                28 Aug 2023, 08:58

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

                P Offline
                P Offline
                Pradson
                wrote on 28 Aug 2023, 11:12 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

                1/7

                28 Aug 2023, 06:06

                • Login

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