Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. new class didn't work correcltly
Qt 6.12 LTS is out! See what's new in the release blog

new class didn't work correcltly

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 1.2k 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.
  • Z Offline
    Z Offline
    Zunneh
    wrote on last edited by
    #1

    Hello guys , i created a new class (Personnage ) which contains a QLabel , and in the Qlabel there are a Pixmap (the green ball ) after this i called this object from another program (it work ) and i created a function in this new class to move my object (i used move which come from QLabel ) but it didn't work , can someone help me please , thanks 1_1550064880338_Capture d’écran 2019-02-13 à 14.19.53.png

    0_1550064880338_Capture d’écran 2019-02-13 à 14.19.21.png

    my english is average, please use simple words and try to be the most explicit, thank you

    JonBJ 1 Reply Last reply
    0
    • Z Zunneh

      Hello guys , i created a new class (Personnage ) which contains a QLabel , and in the Qlabel there are a Pixmap (the green ball ) after this i called this object from another program (it work ) and i created a function in this new class to move my object (i used move which come from QLabel ) but it didn't work , can someone help me please , thanks 1_1550064880338_Capture d’écran 2019-02-13 à 14.19.53.png

      0_1550064880338_Capture d’écran 2019-02-13 à 14.19.21.png

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Zunneh
      I shall be surprised if someone can discern exactly what you are saying here....

      after this i called this object from another program (it work )

      What does that mean? You can't call objects from other programs....

      i created a function in this new class to move my object (i used move which come from QLabel )

      So your code does not move the object (Personnage), it just moves the label within the Personnage widget.... To be specific, your test->move(0, m_y) moves the QLabel within your widget, while the this->move(60, 0) moves your Personnage, which one were you talking about...?

      but it didn't work

      What does that mean...?

      1 Reply Last reply
      1
      • Z Offline
        Z Offline
        Zunneh
        wrote on last edited by Zunneh
        #3

        i created the main program with Qt designer and after this i added a class in this project which contains the green ball , now from the main program (look at the previous screen shot ) i created the object (the green ball whose name is bat) and i want to control this object from main program , i tried but i can' move the object from the main program (i can move it only from the constructor of the class with test->move , me i want to move all the new object Personnage for example when i write bat->movetoUp() it move the object to Up

        0_1550066745903_Capture d’écran 2019-02-13 à 15.00.03.png ")

        my english is average, please use simple words and try to be the most explicit, thank you

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          bat is local to the constructor so can't be referenced outside it. move the Personnage* bat; definition in the header (.h) and in the constructor just put bat = new Personnage(this);. Now you can use bat everywhere in your MainWindow.

          P.S.
          The constructor of Personnage does some weird stuff, basically the label inside Personnage and Personnage have completely distinct lives and that's unusual to say the least

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          2
          • Z Offline
            Z Offline
            Zunneh
            wrote on last edited by
            #5

            i find the solutions , my problem that in the first i put QLabel who is inside Personnage the parent , now i put my Personnage the parent so i can move the personnage not the Qlabel inside the personnage, i added the command this->setParent(parent)
            by the way thank you guys for the help

            0_1550068753833_Capture d’écran 2019-02-13 à 15.36.50.png

            my english is average, please use simple words and try to be the most explicit, thank you

            jsulmJ 1 Reply Last reply
            0
            • Z Zunneh

              i find the solutions , my problem that in the first i put QLabel who is inside Personnage the parent , now i put my Personnage the parent so i can move the personnage not the Qlabel inside the personnage, i added the command this->setParent(parent)
              by the way thank you guys for the help

              0_1550068753833_Capture d’écran 2019-02-13 à 15.36.50.png

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Zunneh There is no need to call setParent, just call base class constructor and pass parent to it:

              Personnage::Personnage(QWidget* parent): QWidget(parent), m_x(0), m_y(0)
              {
              

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

              1 Reply Last reply
              2

              • Login

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