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 to get layout type from base class?
Qt 6.11 is out! See what's new in the release blog

How to get layout type from base class?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 821 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1

    I am supporting all the layouts by storing an instance of the base class, is there a way to determine the type of layout from the base class?

    This is so I know if I can cast the base back to for example QFormLayout to allow use of the form related functions.

    Kind Regards,
    Sy

    jsulmJ 2 Replies Last reply
    0
    • SPlattenS SPlatten

      I am supporting all the layouts by storing an instance of the base class, is there a way to determine the type of layout from the base class?

      This is so I know if I can cast the base back to for example QFormLayout to allow use of the form related functions.

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

      @SPlatten https://doc.qt.io/qt-5/qobject.html#metaObject
      https://doc.qt.io/qt-5/qmetaobject.html#className

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

      SPlattenS 1 Reply Last reply
      2
      • jsulmJ jsulm

        @SPlatten https://doc.qt.io/qt-5/qobject.html#metaObject
        https://doc.qt.io/qt-5/qmetaobject.html#className

        SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by
        #3

        @jsulm thank you

        Kind Regards,
        Sy

        1 Reply Last reply
        0
        • SPlattenS SPlatten

          I am supporting all the layouts by storing an instance of the base class, is there a way to determine the type of layout from the base class?

          This is so I know if I can cast the base back to for example QFormLayout to allow use of the form related functions.

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

          @SPlatten said in How to get layout type from base class?:

          This is so I know if I can cast the base back to for example QFormLayout

          You can always try to cast, if the type is wrong you'll get nullptr.
          https://doc.qt.io/qt-5/qobject.html#qobject_cast

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

          SPlattenS 1 Reply Last reply
          1
          • jsulmJ jsulm

            @SPlatten said in How to get layout type from base class?:

            This is so I know if I can cast the base back to for example QFormLayout

            You can always try to cast, if the type is wrong you'll get nullptr.
            https://doc.qt.io/qt-5/qobject.html#qobject_cast

            SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #5

            @jsulm , I like that idea:

                        QFormLayout* pobjForm(qobject_cast<QFormLayout*>(pobjLayout));
                        QGridLayout* pobjGrid(qobject_cast<QGridLayout*>(pobjLayout));
                        QHBoxLayout* pobjHBox(qobject_cast<QHBoxLayout*>(pobjLayout));
                        QVBoxLayout* pobjVBox(qobject_cast<QVBoxLayout*>(pobjLayout));
            

            Simple and elegant.

            Kind Regards,
            Sy

            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