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. Pointer type conversion
Forum Updated to NodeBB v4.3 + New Features

Pointer type conversion

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 573 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.
  • C Offline
    C Offline
    canid
    wrote on last edited by
    #1

    Hello, what is the base class of the UI class?I want to take the UI base class pointer as a function parameter and use qobject_cast to convert the base class pointer inside the function into a subclass pointer, but the following error is indicated:0_1565088744928_捕获.JPG

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

      Hi
      Its a plain class. Its not QObject based so u cant use qobject_cast

      class Ui_MainWindow
      {
      public:
          QWidget *centralWidget;
          QHBoxLayout *horizontalLayout;
          QTabWidget *tabWidget;
          QWidget *tab;
      
      C 1 Reply Last reply
      2
      • mrjjM mrjj

        Hi
        Its a plain class. Its not QObject based so u cant use qobject_cast

        class Ui_MainWindow
        {
        public:
            QWidget *centralWidget;
            QHBoxLayout *horizontalLayout;
            QTabWidget *tabWidget;
            QWidget *tab;
        
        C Offline
        C Offline
        canid
        wrote on last edited by
        #3

        @mrjj
        static_cast,dynamic_cast,reinterpret_cast are all wrong with it. Is there any other way?

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

          Hi
          Since its just a plain type.
          Im not sure what you are trying to do . There is nothing to cast it to.
          Its not even a QWidget.
          So what are you trying to do ?
          Its very rarely needed to send that private class to anyone. Its internal detail.

          1 Reply Last reply
          2
          • fcarneyF Offline
            fcarneyF Offline
            fcarney
            wrote on last edited by
            #5

            @canid
            Show some minimal code. Its very hard to reason about code we cannot see.

            C++ is a perfectly valid school of magic.

            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