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. [Solved] Cannot cast QObject subclass to QObject
Forum Updated to NodeBB v4.3 + New Features

[Solved] Cannot cast QObject subclass to QObject

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 4.7k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    Asperamanca
    wrote on last edited by
    #1

    I have a class that derives from QGraphicsWidget, and thereby from QObject.

    When attempting to cast a pointer to that class to a QObject pointer, I get a compiler error in VS 2010:

    error C2440: 'static_cast' : cannot convert from 'HIPASE::CTpic_GraphicsDisplayRootElementWidget *' to 'QObject *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

    My class contains the Q_OBJECT macro, and public QGraphicsWidget is first in the list of base classes.

    Any ideas?

    1 Reply Last reply
    1
    • A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      Error was: I only forward-declared the class, didn't include the header

      1 Reply Last reply
      1

      • Login

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