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. createEditor of a custom widget is not being called. How to debug?
Qt 6.11 is out! See what's new in the release blog

createEditor of a custom widget is not being called. How to debug?

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 4 Posters 1.2k Views 2 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.
  • A Offline
    A Offline
    andi456
    wrote on last edited by
    #7

    To be more precise, the mentioned std::vector<int>, that's somehow empty, is a private field of the corresponding model. The aforementioned star delegate example also makes intensive use of such private fields in its class definitions. Should I consider this bad practice, too?

    JonBJ 1 Reply Last reply
    0
    • A andi456

      To be more precise, the mentioned std::vector<int>, that's somehow empty, is a private field of the corresponding model. The aforementioned star delegate example also makes intensive use of such private fields in its class definitions. Should I consider this bad practice, too?

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

      @andi456 said in createEditor of a custom widget is not being called. How to debug?:

      the mentioned std::vector<int>, that's somehow empty, is a private field of the corresponding model.

      So isn't that exactly the shadowing I suggested? If you declare a variable in an inner scope (e.g. inside a class when you have a global, or inside a function where you have a global or class member) of the same name as an outer scope you access the inner one, unless you do something to access the outer one (e.g. this->... or ::...). This is all basic C++.

      If star delegate example is using private variables I very much doubt they are using globals or have got their code wrong. If yours is wrong (as it sounds) then you must fix it. Why would you declare a local/member variable with the same name if you have some global you want to access instead? Better yet don't use a global in the first place.

      A 1 Reply Last reply
      1
      • JonBJ JonB

        @andi456 said in createEditor of a custom widget is not being called. How to debug?:

        the mentioned std::vector<int>, that's somehow empty, is a private field of the corresponding model.

        So isn't that exactly the shadowing I suggested? If you declare a variable in an inner scope (e.g. inside a class when you have a global, or inside a function where you have a global or class member) of the same name as an outer scope you access the inner one, unless you do something to access the outer one (e.g. this->... or ::...). This is all basic C++.

        If star delegate example is using private variables I very much doubt they are using globals or have got their code wrong. If yours is wrong (as it sounds) then you must fix it. Why would you declare a local/member variable with the same name if you have some global you want to access instead? Better yet don't use a global in the first place.

        A Offline
        A Offline
        andi456
        wrote on last edited by
        #9

        @JonB Maybe, it's a matter of terminology, I'm not sure. If you have a look at starrating.h and starrating.cpp, you'll notice two private fields

            QPolygonF starPolygon;
            QPolygonF diamondPolygon;
        

        both are being populated in the constructor:

        StarRating::StarRating(int starCount, int maxStarCount)
            : myStarCount(starCount),
              myMaxStarCount(maxStarCount)
        {
            starPolygon << QPointF(1.0, 0.5);
            for (int i = 1; i < 5; ++i)
                starPolygon << QPointF(0.5 + 0.5 * std::cos(0.8 * i * 3.14),
                                       0.5 + 0.5 * std::sin(0.8 * i * 3.14));
        
            diamondPolygon << QPointF(0.4, 0.5) << QPointF(0.5, 0.4)
                           << QPointF(0.6, 0.5) << QPointF(0.5, 0.6)
                           << QPointF(0.4, 0.5);
        }
        

        Is this bad practice? I have done more or less the same in my model constructor...

        JonBJ Pl45m4P 2 Replies Last reply
        0
        • A andi456

          @JonB Maybe, it's a matter of terminology, I'm not sure. If you have a look at starrating.h and starrating.cpp, you'll notice two private fields

              QPolygonF starPolygon;
              QPolygonF diamondPolygon;
          

          both are being populated in the constructor:

          StarRating::StarRating(int starCount, int maxStarCount)
              : myStarCount(starCount),
                myMaxStarCount(maxStarCount)
          {
              starPolygon << QPointF(1.0, 0.5);
              for (int i = 1; i < 5; ++i)
                  starPolygon << QPointF(0.5 + 0.5 * std::cos(0.8 * i * 3.14),
                                         0.5 + 0.5 * std::sin(0.8 * i * 3.14));
          
              diamondPolygon << QPointF(0.4, 0.5) << QPointF(0.5, 0.4)
                             << QPointF(0.6, 0.5) << QPointF(0.5, 0.6)
                             << QPointF(0.4, 0.5);
          }
          

          Is this bad practice? I have done more or less the same in my model constructor...

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

          @andi456
          I really don't know what you are thinking of. I don't see where terminology comes into anything. The code shown is just fine. Populating private members in constructor is more than usual. And nothing we are discussing has any relevance to whether you have a class to do with a model or anything else.

          You may assume as a rule of thumb that the Qt examples are reasonable C++ coding.

          Your problem is (a) having a global variable in the first place and (b) having a member variable with the same name as the global.

          1 Reply Last reply
          1
          • A andi456

            @JonB Maybe, it's a matter of terminology, I'm not sure. If you have a look at starrating.h and starrating.cpp, you'll notice two private fields

                QPolygonF starPolygon;
                QPolygonF diamondPolygon;
            

            both are being populated in the constructor:

            StarRating::StarRating(int starCount, int maxStarCount)
                : myStarCount(starCount),
                  myMaxStarCount(maxStarCount)
            {
                starPolygon << QPointF(1.0, 0.5);
                for (int i = 1; i < 5; ++i)
                    starPolygon << QPointF(0.5 + 0.5 * std::cos(0.8 * i * 3.14),
                                           0.5 + 0.5 * std::sin(0.8 * i * 3.14));
            
                diamondPolygon << QPointF(0.4, 0.5) << QPointF(0.5, 0.4)
                               << QPointF(0.6, 0.5) << QPointF(0.5, 0.6)
                               << QPointF(0.4, 0.5);
            }
            

            Is this bad practice? I have done more or less the same in my model constructor...

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by Pl45m4
            #11

            @andi456 said in createEditor of a custom widget is not being called. How to debug?:

            Is this bad practice? I have done more or less the same in my model constructor...

            In your example this

            starPolygon << QPointF(1.0, 0.5);
            

            accesses this

               QPolygonF starPolygon;
            

            which is not a global variable.

            @andi456 said in createEditor of a custom widget is not being called. How to debug?:

            Anyway, it's strange that a globally declared vector loses its contents in one particular model and not in others

            Here you wrote you use a globally declared vector... which is not the same as used in the example.
            Or are you refering to the above code as "globally declared"... then it's wrong terminology because globally declared is something like:

            // global counter
            int counter = 0;
            
            class A
            {
               A();
            
            private:
               // private counter as a class member
               int counter;
            };
            

            writing counter = 42; in you a.cpp would shadow the private member counter cause it's ambiguous and it's not clear if you want to set the global counter to 42 or the private member of class A.


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            1
            • A Offline
              A Offline
              andi456
              wrote on last edited by
              #12

              Mea culpa, mea maxima culpa, I used the wrong notion of "global variable", sorry for that. Private field would have been better, I suppose.

              Well, I don't know what exactly interferes with the std::vector<int> field, which is not visible outside the model, but as the star delegate example code is okay, I will stick with std::map solution, which is analogous....

              Pl45m4P 1 Reply Last reply
              0
              • A andi456

                Mea culpa, mea maxima culpa, I used the wrong notion of "global variable", sorry for that. Private field would have been better, I suppose.

                Well, I don't know what exactly interferes with the std::vector<int> field, which is not visible outside the model, but as the star delegate example code is okay, I will stick with std::map solution, which is analogous....

                Pl45m4P Offline
                Pl45m4P Offline
                Pl45m4
                wrote on last edited by
                #13

                @andi456 said in createEditor of a custom widget is not being called. How to debug?:

                Well, I don't know what exactly interferes with the std::vector<int> field

                How are you passing the the vector around?


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andi456
                  wrote on last edited by
                  #14

                  No, I just populate it in the model constructor in a somewhat cumbersome manner. After that it is only being used in the flags method of the model. As I said, it is a little strange, because the approach works in the other models of the application...

                  JonBJ 1 Reply Last reply
                  0
                  • A andi456

                    No, I just populate it in the model constructor in a somewhat cumbersome manner. After that it is only being used in the flags method of the model. As I said, it is a little strange, because the approach works in the other models of the application...

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

                    @andi456 So do you want to show the code that does not work so someone can comment/explain?

                    1 Reply Last reply
                    1
                    • A Offline
                      A Offline
                      andi456
                      wrote on last edited by andi456
                      #16

                      Actually, I've begun to put the std::map approach to use it in the other models too, because it is much less awkward. When I'm done with that, I will show the code especially, if I encounter any errors. Thanks for your help, anyway.

                      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