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. Issues with getter and setter methods
Forum Updated to NodeBB v4.3 + New Features

Issues with getter and setter methods

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 6 Posters 731 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.
  • SGaistS SGaist

    @ddryomyss said in Issues with getter and setter methods:

    void MainWindow::mousePressEvent(QMouseEvent *mpe)
    {
    paintScene ps;

    ps is local to that function. Hence it's going to be empty and also destroyed a the end of the function.

    ddryomyssD Offline
    ddryomyssD Offline
    ddryomyss
    wrote on last edited by
    #3

    @SGaist and so? I don't really get, why ps.get() do not return to the value of start_pt.

    If I will describe get() function like that:

    bool paintScene::get()
    {
        return true;
    }
    

    numeration will work. Where is the problem?

    J.HilkJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #4

      The issue is your understanding of the variable scope. As I already said, you create a function local object of the type paintScene. You are getting the correct value since it's initialised to false.

      You should be using your class instance of paintScene.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • ddryomyssD ddryomyss

        @SGaist and so? I don't really get, why ps.get() do not return to the value of start_pt.

        If I will describe get() function like that:

        bool paintScene::get()
        {
            return true;
        }
        

        numeration will work. Where is the problem?

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by J.Hilk
        #5

        @ddryomyss you didn't read up on your basics, like I suggested in your other thread!

        What you did, is:

        You're in your house, and you create a box there. The box was empty, so you placed a banana in it.

        Then you went to your garden shed and leave your box behind. But now you're missing your box! So you create an other a box there, the same way you did in your house. Its also empty, but you're now wondering why there's no banana in!


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        JonBJ ddryomyssD 3 Replies Last reply
        5
        • J.HilkJ J.Hilk

          @ddryomyss you didn't read up on your basics, like I suggested in your other thread!

          What you did, is:

          You're in your house, and you create a box there. The box was empty, so you placed a banana in it.

          Then you went to your garden shed and leave your box behind. But now you're missing your box! So you create an other a box there, the same way you did in your house. Its also empty, but you're now wondering why there's no banana in!

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

          @J-Hilk
          Very good analogy! But would this apply to apples too, or is it banana-specific?

          J.HilkJ 1 Reply Last reply
          1
          • JonBJ JonB

            @J-Hilk
            Very good analogy! But would this apply to apples too, or is it banana-specific?

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #7

            @JonB no, Bananas and Oranges only!

            The solution btw, is to go the the window, rise your hand and point at your house and order your first box to come the f over :D


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            3
            • J.HilkJ J.Hilk

              @ddryomyss you didn't read up on your basics, like I suggested in your other thread!

              What you did, is:

              You're in your house, and you create a box there. The box was empty, so you placed a banana in it.

              Then you went to your garden shed and leave your box behind. But now you're missing your box! So you create an other a box there, the same way you did in your house. Its also empty, but you're now wondering why there's no banana in!

              ddryomyssD Offline
              ddryomyssD Offline
              ddryomyss
              wrote on last edited by
              #8

              @J-Hilk It finally clicked in my head, thank you so much, it was such a nice analogy!

              1 Reply Last reply
              0
              • J.HilkJ J.Hilk

                @ddryomyss you didn't read up on your basics, like I suggested in your other thread!

                What you did, is:

                You're in your house, and you create a box there. The box was empty, so you placed a banana in it.

                Then you went to your garden shed and leave your box behind. But now you're missing your box! So you create an other a box there, the same way you did in your house. Its also empty, but you're now wondering why there's no banana in!

                ddryomyssD Offline
                ddryomyssD Offline
                ddryomyss
                wrote on last edited by
                #9

                @J-Hilk I know that I am weak with basics. I was kind of forced to jump right into practice, so now it hurts badly a lot of times (lack of basic knowledge, I mean). Maybe you have any recommendations on sources of info? Something like a clear study plan (maybe a book, or course of lectures). Or maybe there was a post here on this topic? I'll be grateful to hear any recommendations from you (:

                J.HilkJ 1 Reply Last reply
                2
                • KH-219DesignK Offline
                  KH-219DesignK Offline
                  KH-219Design
                  wrote on last edited by
                  #10

                  If I may be so bold as to suddenly insert myself...

                  @ddryomyss It is refreshing and heartening to see you acknowledge your weaknesses. That takes a certain courage, and I commend you!

                  My workplace study-group (all full-time professional software and firmware engineers) recently brainstormed a book list. We found there was great overlap when we each listed the books that had had the biggest influence on each of us.

                  I'll paste a relevant excerpt here.

                  I'd like to explicitly note: some of the books from 10+ years ago are still extremely relevant! Don't automatically discount any of these due to publication date alone.

                  For the C++ language specifically, please choose from this other list: https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list

                  For widely-applicable software craft advice:

                  (2004) Head First Design Patterns

                  (2004) An Introduction to GCC <--- excellent for understanding how code turns into libraries and executables (whether or not you use GCC. the principles hold even on Windows in Visual Studio)

                  (2005) Effective C++ (definitely get the 3rd edition)

                  (2008) Clean Code

                  (2009) The Passionate Programmer

                  (2014) Effective Modern C++

                  www.219design.com
                  Software | Electrical | Mechanical | Product Design

                  ddryomyssD 1 Reply Last reply
                  1
                  • W Offline
                    W Offline
                    wrosecrans
                    wrote on last edited by
                    #11

                    The simplest explanation of scope I've seen for students is that a set of { ... } curly braces in C++ are like Las Vegas. What happens in curly braces stays in curly braces!

                    1 Reply Last reply
                    0
                    • ddryomyssD ddryomyss

                      @J-Hilk I know that I am weak with basics. I was kind of forced to jump right into practice, so now it hurts badly a lot of times (lack of basic knowledge, I mean). Maybe you have any recommendations on sources of info? Something like a clear study plan (maybe a book, or course of lectures). Or maybe there was a post here on this topic? I'll be grateful to hear any recommendations from you (:

                      J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #12

                      @ddryomyss said in Issues with getter and setter methods:

                      @J-Hilk I know that I am weak with basics. I was kind of forced to jump right into practice, so now it hurts badly a lot of times (lack of basic knowledge, I mean).

                      Don't worry, I started in a very similar fashion myself, I can relate.
                      As long as you're hopeful, polite and most importantly willing to improve yourself, I'm sure no-one here will refuse to aide you!

                      Maybe you have any recommendations on sources of info? Something like a clear study plan (maybe a book, or course of lectures). Or maybe there was a post here on this topic? I'll be grateful to hear any recommendations from you (:

                      Well, I can only tell you from my personal experience.
                      I learn the more from videos than from books. So I've a couple of YT channels, that I follow that over the years published a hand full of tutorials:

                      I can recommend the following:
                      The Cherno:
                      https://www.youtube.com/c/TheChernoProject

                      he's a previous (c++)Game Developer and has a playlist about the basics (still ongoing) an OpenGL tutorial playlist and a GameEngine developer playlist.
                      So it varies between beginner level entry and advanced, pick your poison carefully

                      VoidRealms:
                      https://www.youtube.com/user/VoidRealms

                      He's also a (somewhat) active forum member, he was one of my first Qt related sources for me.
                      Also has introductions to C++ and other Languages, and last I heard he has udemy courses to offer (never checked them out myself!)

                      Cᐩᐩ Weekly:
                      https://www.youtube.com/user/lefticus1

                      For more advanced stuff and oddities in c++, :D


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      1 Reply Last reply
                      3
                      • KH-219DesignK KH-219Design

                        If I may be so bold as to suddenly insert myself...

                        @ddryomyss It is refreshing and heartening to see you acknowledge your weaknesses. That takes a certain courage, and I commend you!

                        My workplace study-group (all full-time professional software and firmware engineers) recently brainstormed a book list. We found there was great overlap when we each listed the books that had had the biggest influence on each of us.

                        I'll paste a relevant excerpt here.

                        I'd like to explicitly note: some of the books from 10+ years ago are still extremely relevant! Don't automatically discount any of these due to publication date alone.

                        For the C++ language specifically, please choose from this other list: https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list

                        For widely-applicable software craft advice:

                        (2004) Head First Design Patterns

                        (2004) An Introduction to GCC <--- excellent for understanding how code turns into libraries and executables (whether or not you use GCC. the principles hold even on Windows in Visual Studio)

                        (2005) Effective C++ (definitely get the 3rd edition)

                        (2008) Clean Code

                        (2009) The Passionate Programmer

                        (2014) Effective Modern C++

                        ddryomyssD Offline
                        ddryomyssD Offline
                        ddryomyss
                        wrote on last edited by
                        #13

                        @KH-219Design @J-Hilk I'm truly amazed by your willingness to share your experience with me! I'll try to make maximum use of your recommendations as soon as I can, huuuge thank you (:

                        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 Extensions
                        • Unsolved