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. Class Promotion ?
Qt 6.11 is out! See what's new in the release blog

Class Promotion ?

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 3 Posters 7.0k Views 3 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #11

    You mean events that have been sent to A but haven't been "delivered" to it yet?

    1 Reply Last reply
    0
    • W Offline
      W Offline
      Walux
      wrote on last edited by
      #12

      Yes , how can i assign all of them to the new class B ?

      Taking things from beginning to end : That's my entertainment !

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #13

        Call QCoreApplication::processEvents before destroying A.

        W 1 Reply Last reply
        0
        • mrjjM mrjj

          @Walux
          the simple version is
          class Master
          all variables..

          class A : Master
          paintEvent

          class B : Master
          paintEvent

          the more lame is
          class A :B
          PaintAsA(QPainter *)
          PaintAsB(QPainter *)

          paintevent(...)
          if(UseB)
          PaintAsB
          else
          PaintAsA

          which is bad with more sublasses

          W Offline
          W Offline
          Walux
          wrote on last edited by
          #14

          @mrjj

          Maybe i should do this instead :

          I start by creating a class B that uses the paintEvent of class A , then when i reach the certain state , it calls the paintEvent of class B .

          I have no problem doing it now , since the difference is only in the painting , but later when the new classes have new variables , that'll be a problem .

          Taking things from beginning to end : That's my entertainment !

          1 Reply Last reply
          0
          • ? A Former User

            Call QCoreApplication::processEvents before destroying A.

            W Offline
            W Offline
            Walux
            wrote on last edited by
            #15

            @Wieland

            Maybe a small piece of code will help me understand better , and thank you :)

            Taking things from beginning to end : That's my entertainment !

            1 Reply Last reply
            0
            • W Offline
              W Offline
              Walux
              wrote on last edited by
              #16

              I'm sure the answer i'm looking for lays somewhere between :

              • dynamic_cast
              • virtual
              • operator=

              Taking things from beginning to end : That's my entertainment !

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

                I dont understand why it ever need to change "type".
                I think you need to rethink the design.
                Normally u use base class pointers and childs for polymorph operations but
                i cannot understand your use case.

                Its like circle that must sudden draw as a rect?

                W 1 Reply Last reply
                0
                • mrjjM mrjj

                  I dont understand why it ever need to change "type".
                  I think you need to rethink the design.
                  Normally u use base class pointers and childs for polymorph operations but
                  i cannot understand your use case.

                  Its like circle that must sudden draw as a rect?

                  W Offline
                  W Offline
                  Walux
                  wrote on last edited by Walux
                  #18

                  @mrjj
                  @Wieland

                  I'll try to minimize the code , to help clarify my situation :

                  Class myScene : public QGraphicsScene
                  {
                  //...
                  void MousePressEvent(QGraphicsSceneMouseEvent *event)
                  //...
                  private:
                  A *a;
                  //...
                  }
                  

                  "myScene.cpp"

                  myScene::myScene 
                  {
                  a = new A;
                  }
                  
                  void  myScene::MousePressEvent(QGraphicsSceneMouseEvent *event)
                  {
                  a->doesSmth();
                  if(a->reachesSomePoint())
                  a = new B;   // Compiles good but i lose the events and the whole paint of a;
                  }
                  
                  Class A : public QObject , public QGraphicsItem
                  {
                  //...
                      A();
                      QRectF boundingRect() const Q_DECL_OVERRIDE;
                      QPainterPath shape() const Q_DECL_OVERRIDE;
                      void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
                                 QWidget *widget) Q_DECL_OVERRIDE; // This is the first painting
                  
                      
                  //...
                        protected:
                  qreal myValue1;
                  int myValue2;
                  //...
                  }
                  
                  Class B : public Class A
                  {
                          void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
                                 QWidget *widget) Q_DECL_OVERRIDE; // This is the second painting
                  //Future Variables
                         private:
                  qreal futureValue1;
                  //...
                  }
                  

                  Taking things from beginning to end : That's my entertainment !

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

                    hi
                    You only need to go from base to child?
                    You can use a cast for that.
                    http://www.bogotobogo.com/cplusplus/upcasting_downcasting.php

                    and you dont lose A paint as you are free to call the A::paintEvent from
                    B::paintEvent.

                    W 1 Reply Last reply
                    1
                    • mrjjM mrjj

                      hi
                      You only need to go from base to child?
                      You can use a cast for that.
                      http://www.bogotobogo.com/cplusplus/upcasting_downcasting.php

                      and you dont lose A paint as you are free to call the A::paintEvent from
                      B::paintEvent.

                      W Offline
                      W Offline
                      Walux
                      wrote on last edited by
                      #20

                      @mrjj

                      Thanks for your help , glad you stayed with me till the bottom ;)
                      Imma read the content of your link :)

                      Taking things from beginning to end : That's my entertainment !

                      1 Reply Last reply
                      1
                      • W Offline
                        W Offline
                        Walux
                        wrote on last edited by
                        #21

                        Hmm , very informative , and i can get the slicing problem now :)
                        But , it won't be of any harm till late versions of my program :)
                        Thank you very much :D

                        Topic->setAsSloved(true);

                        Taking things from beginning to end : That's my entertainment !

                        mrjjM 1 Reply Last reply
                        0
                        • W Walux

                          Hmm , very informative , and i can get the slicing problem now :)
                          But , it won't be of any harm till late versions of my program :)
                          Thank you very much :D

                          Topic->setAsSloved(true);

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #22

                          @Walux
                          Np.
                          Its not always you run into slicing but its good to know it can happen.

                          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