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. std vector, QVector and fields..

std vector, QVector and fields..

Scheduled Pinned Locked Moved Unsolved General and Desktop
29 Posts 6 Posters 4.5k 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.
  • J J.Hilk
    29 Oct 2020, 06:28

    @JonB said in std vector, QVector and fields..:

    I need to apply some initial changes to all of them, to do with aligning, coloring. delegating & connecting slots.

    You know, if all those operations are constexpr-able you could do them during compile time!
    Ha dreams 😥

    J Online
    J Online
    JonB
    wrote on 29 Oct 2020, 07:01 last edited by JonB
    #15

    @J-Hilk
    Not sure what you mean. Even if they are, the question we are debating is: how do you apply them across 47 design-time (non-subclassed) separate QSpinBoxes? And maintain for future ones which might be added? I'm not prepared to write it against 47 member variables, if I put them into a list/array/vector I have to write/maintain that which equally I don't want to do, so leaves me with QObject::findChildren<QCheckBox *> as the easiest way to implement. Which @Chris-Kawa has informed me will kill my beloved pussy cat, so I feel terrible :(

    J 1 Reply Last reply 29 Oct 2020, 07:11
    0
    • J JonB
      29 Oct 2020, 07:01

      @J-Hilk
      Not sure what you mean. Even if they are, the question we are debating is: how do you apply them across 47 design-time (non-subclassed) separate QSpinBoxes? And maintain for future ones which might be added? I'm not prepared to write it against 47 member variables, if I put them into a list/array/vector I have to write/maintain that which equally I don't want to do, so leaves me with QObject::findChildren<QCheckBox *> as the easiest way to implement. Which @Chris-Kawa has informed me will kill my beloved pussy cat, so I feel terrible :(

      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 29 Oct 2020, 07:11 last edited by J.Hilk
      #16

      @JonB
      you said

      I need to apply some initial changes to all of them

      which means, you know (theoretically) during compile time what your values should be.

      Now, if all your functions on QCheckBox were constexpr and find children would be as well, you could create a small constexpr function of your own, that finds all QCheckBox and sets the initial values and call that somewhere early on. The compiler would evaluate those calls during compile time and set the initial values accordingly without runtime overhead.


      no kittens required to die, in fact you would have more time, due to longer compile times, to pet them


      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.

      J 1 Reply Last reply 29 Oct 2020, 07:21
      0
      • J J.Hilk
        29 Oct 2020, 07:11

        @JonB
        you said

        I need to apply some initial changes to all of them

        which means, you know (theoretically) during compile time what your values should be.

        Now, if all your functions on QCheckBox were constexpr and find children would be as well, you could create a small constexpr function of your own, that finds all QCheckBox and sets the initial values and call that somewhere early on. The compiler would evaluate those calls during compile time and set the initial values accordingly without runtime overhead.


        no kittens required to die, in fact you would have more time, due to longer compile times, to pet them

        J Online
        J Online
        JonB
        wrote on 29 Oct 2020, 07:21 last edited by JonB
        #17

        @J-Hilk said in std vector, QVector and fields..:

        you could create a small constexpr function of your own, that finds all QCheckBox

        Not that I can imagine doing this, but could you give an example of how I would do this, at compile-time? Or is that based on a hypothetical "if all your functions on QCheckBox were constexpr and find children would be as well"? I don't follow how you would get a list at compile-time of all QCheckBoxes I have created in Designer (without my having to type that into the source code manually)?

        J 1 Reply Last reply 29 Oct 2020, 07:28
        0
        • J JonB
          29 Oct 2020, 07:21

          @J-Hilk said in std vector, QVector and fields..:

          you could create a small constexpr function of your own, that finds all QCheckBox

          Not that I can imagine doing this, but could you give an example of how I would do this, at compile-time? Or is that based on a hypothetical "if all your functions on QCheckBox were constexpr and find children would be as well"? I don't follow how you would get a list at compile-time of all QCheckBoxes I have created in Designer (without my having to type that into the source code manually)?

          J Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 29 Oct 2020, 07:28 last edited by J.Hilk
          #18

          @JonB it is hypothetical, because I'm pretty sure setupUi is not constexpr

          but as example, take this compiletime calculation of fibonacci

          constexpr int64_t fibonacci(const int64_t  n)
          {
              return n < 1 ? -1 :
                  (n == 1 || n == 2 ? 1 : fibonacci(n - 1) + fibonacci(n - 2));
          }
          
          int main (int argc, char *argv[])
          {
              constexpr auto evaled = fibonacci(25);
                  return evaled;
          }
          

          actually had to modify the example to force the compiletime evaluation , a little bit finicky the whole system (still)


          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.

          J 1 Reply Last reply 29 Oct 2020, 07:39
          1
          • J J.Hilk
            29 Oct 2020, 07:28

            @JonB it is hypothetical, because I'm pretty sure setupUi is not constexpr

            but as example, take this compiletime calculation of fibonacci

            constexpr int64_t fibonacci(const int64_t  n)
            {
                return n < 1 ? -1 :
                    (n == 1 || n == 2 ? 1 : fibonacci(n - 1) + fibonacci(n - 2));
            }
            
            int main (int argc, char *argv[])
            {
                constexpr auto evaled = fibonacci(25);
                    return evaled;
            }
            

            actually had to modify the example to force the compiletime evaluation , a little bit finicky the whole system (still)

            J Online
            J Online
            JonB
            wrote on 29 Oct 2020, 07:39 last edited by JonB
            #19

            @J-Hilk
            OK, yes, I know about turning the C++ compiler into an interpreter with constexpr :) But that fibonacci function is self-contained. Compiler is not going to be able to execute anything like constexpr QObject::findChildren<QCheckBox *>, it's runtime-only.

            Purely BTW. I'm not a great programmer (nor mathematician), so while I develop my code I have a go at:

            constexpr int64_t fibonacci(const int64_t  n)
            {
                int64_t result = 0;
                while (n > 0)
                    result += n;
                return result;
            }
            

            Now I compile my code. Does the compilation simply hang??

            J 1 Reply Last reply 29 Oct 2020, 07:41
            0
            • J JonB
              29 Oct 2020, 07:39

              @J-Hilk
              OK, yes, I know about turning the C++ compiler into an interpreter with constexpr :) But that fibonacci function is self-contained. Compiler is not going to be able to execute anything like constexpr QObject::findChildren<QCheckBox *>, it's runtime-only.

              Purely BTW. I'm not a great programmer (nor mathematician), so while I develop my code I have a go at:

              constexpr int64_t fibonacci(const int64_t  n)
              {
                  int64_t result = 0;
                  while (n > 0)
                      result += n;
                  return result;
              }
              

              Now I compile my code. Does the compilation simply hang??

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 29 Oct 2020, 07:41 last edited by jsulm
              #20

              @JonB said in std vector, QVector and fields..:

              Now I compile my code. Does the compilation simply hang??

              No, because you're not calling it :-)
              And it would not hang if you would call it with any number as parameter. It could probably slow down compilation if you would pass a huge number :-)

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

              J 1 Reply Last reply 29 Oct 2020, 07:43
              0
              • J jsulm
                29 Oct 2020, 07:41

                @JonB said in std vector, QVector and fields..:

                Now I compile my code. Does the compilation simply hang??

                No, because you're not calling it :-)
                And it would not hang if you would call it with any number as parameter. It could probably slow down compilation if you would pass a huge number :-)

                J Online
                J Online
                JonB
                wrote on 29 Oct 2020, 07:43 last edited by JonB
                #21

                @jsulm
                Oh yes I am! In @J-Hilk's code (at least originally) his main() calls fibonacci(10), so assume that, and then tell me what happens while I sit waiting for the compilation to finish?

                And it would not hang if you would call it with any number as parameter. It could probably slow down compilation if you would pass a huge number :-)

                I think you should look at the code again... :)

                J J 2 Replies Last reply 29 Oct 2020, 07:45
                1
                • J JonB
                  29 Oct 2020, 07:43

                  @jsulm
                  Oh yes I am! In @J-Hilk's code (at least originally) his main() calls fibonacci(10), so assume that, and then tell me what happens while I sit waiting for the compilation to finish?

                  And it would not hang if you would call it with any number as parameter. It could probably slow down compilation if you would pass a huge number :-)

                  I think you should look at the code again... :)

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 29 Oct 2020, 07:45 last edited by
                  #22

                  @JonB OK, I see n > 0. You should try :-)

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

                  J 1 Reply Last reply 29 Oct 2020, 07:48
                  1
                  • J JonB
                    29 Oct 2020, 07:43

                    @jsulm
                    Oh yes I am! In @J-Hilk's code (at least originally) his main() calls fibonacci(10), so assume that, and then tell me what happens while I sit waiting for the compilation to finish?

                    And it would not hang if you would call it with any number as parameter. It could probably slow down compilation if you would pass a huge number :-)

                    I think you should look at the code again... :)

                    J Offline
                    J Offline
                    J.Hilk
                    Moderators
                    wrote on 29 Oct 2020, 07:46 last edited by J.Hilk
                    #23

                    @JonB Add at least a function call to your calculation, then you get an stack overflow(eventually)


                    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.

                    J 1 Reply Last reply 29 Oct 2020, 07:49
                    0
                    • J jsulm
                      29 Oct 2020, 07:45

                      @JonB OK, I see n > 0. You should try :-)

                      J Online
                      J Online
                      JonB
                      wrote on 29 Oct 2020, 07:48 last edited by
                      #24

                      @jsulm

                      You should try :-)

                      I'm terrified of seizing up my Linux VM :) It already does that if I accidentally debug from Creator when inside a QComboBox clicked slot, and I have to hard-switch-off the whole VM... :(

                      J 1 Reply Last reply 29 Oct 2020, 07:49
                      0
                      • J JonB
                        29 Oct 2020, 07:48

                        @jsulm

                        You should try :-)

                        I'm terrified of seizing up my Linux VM :) It already does that if I accidentally debug from Creator when inside a QComboBox clicked slot, and I have to hard-switch-off the whole VM... :(

                        J Offline
                        J Offline
                        J.Hilk
                        Moderators
                        wrote on 29 Oct 2020, 07:49 last edited by
                        #25

                        @JonB

                        main.cpp:158:18: error: expression is not an integral constant expression
                        main.cpp:152:13: note: constexpr evaluation hit maximum step limit; possible infinite loop?
                        main.cpp:158:18: note: in call to 'fibonacci(25)'
                        

                        smart things these compilers


                        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.

                        J 1 Reply Last reply 29 Oct 2020, 07:50
                        1
                        • J J.Hilk
                          29 Oct 2020, 07:46

                          @JonB Add at least a function call to your calculation, then you get an stack overflow(eventually)

                          J Online
                          J Online
                          JonB
                          wrote on 29 Oct 2020, 07:49 last edited by
                          #26

                          @J-Hilk said in std vector, QVector and fields..:

                          @JonB Add at least a function call to your calculation, then you get an stack overflow(eventually)

                          But I don't want a stackoverflow to terminate! I want to know whether the compiler sits there forever! Which is why I wrote as I did.

                          OK, I'm off to try....

                          1 Reply Last reply
                          0
                          • J J.Hilk
                            29 Oct 2020, 07:49

                            @JonB

                            main.cpp:158:18: error: expression is not an integral constant expression
                            main.cpp:152:13: note: constexpr evaluation hit maximum step limit; possible infinite loop?
                            main.cpp:158:18: note: in call to 'fibonacci(25)'
                            

                            smart things these compilers

                            J Online
                            J Online
                            JonB
                            wrote on 29 Oct 2020, 07:50 last edited by
                            #27

                            @J-Hilk said in std vector, QVector and fields..:

                            note: constexpr evaluation hit maximum step limit; possible infinite loop?

                            Ah ha! So..... this C++ constexpr has what "maximum step limit`? Where is that in the spec? :)

                            J 1 Reply Last reply 29 Oct 2020, 07:52
                            0
                            • J JonB
                              29 Oct 2020, 07:50

                              @J-Hilk said in std vector, QVector and fields..:

                              note: constexpr evaluation hit maximum step limit; possible infinite loop?

                              Ah ha! So..... this C++ constexpr has what "maximum step limit`? Where is that in the spec? :)

                              J Offline
                              J Offline
                              J.Hilk
                              Moderators
                              wrote on 29 Oct 2020, 07:52 last edited by
                              #28

                              @JonB up to you with the compiler option -fconstexpr-steps


                              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.

                              J 1 Reply Last reply 29 Oct 2020, 07:56
                              0
                              • J J.Hilk
                                29 Oct 2020, 07:52

                                @JonB up to you with the compiler option -fconstexpr-steps

                                J Online
                                J Online
                                JonB
                                wrote on 29 Oct 2020, 07:56 last edited by
                                #29

                                @J-Hilk
                                Wow! They think of everything! I wonder if that would accept -fconstexpr-steps fibonacci(25) ;-)

                                OK, enough now, thanks!

                                1 Reply Last reply
                                0

                                24/29

                                29 Oct 2020, 07:48

                                • Login

                                • Login or register to search.
                                24 out of 29
                                • First post
                                  24/29
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved