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. How do I do a dynamic_cast on a QSharedDataPointer?

How do I do a dynamic_cast on a QSharedDataPointer?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 399 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.
  • T Offline
    T Offline
    twodee
    wrote on last edited by
    #1

    Based on the suggestions on my last post, I have started using QSharedDataPointers instead of QList<Class*>, but this has brought up a new problem while trying to dynamic_cast data to this type.

    I have a QList<QGraphicsItem*>::iterator itr

    Layer* l = dynamic_cast<Layer*>(*itr);
    

    I am trying to do something like:

    Layer::LayerPointer l = dynamic_cast<Layer::LayerPointer>(*itr);
    

    LayerPointer has been defined here:

    typedef QSharedDataPointer<Layer> LayerPointer;
    

    For obvious reasons I am getting a "Cannot dynamic_cast... target is not pointer or reference"

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      you can use
      http://doc.qt.io/qt-5/qshareddatapointer.html#data
      http://doc.qt.io/qt-5/qshareddatapointer.html#constData
      to get type T ( the actual pointer )
      ( there might be better way)
      Im wondering however if dynamic_cast is right to use and not
      qgraphicsitem_cast ?

      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