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. Loops [solved]
Forum Updated to NodeBB v4.3 + New Features

Loops [solved]

Scheduled Pinned Locked Moved General and Desktop
12 Posts 5 Posters 3.5k Views 1 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.
  • R Offline
    R Offline
    RichardM198030
    wrote on last edited by
    #3

    [quote author="peppe" date="1315155068"]But... what's exactly the question? What are you trying to achieve?[/quote]

    Just to get those 4 variables to display in a QComboBox.

    [code]

    QComboBox *comboBox;

    [/code]

    That's all, like I said, I'm confused here, and can't really answer your question, sorry.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #4

      from what I gather, what you need is a basic book about programming. Doesn't even have to be on C++.

      Some more code for you:
      @
      QComboBox *comboBox;
      comboBox = new QComboBox();

      for (i = 0; i < 4; i++) {
      comboBox.addItem(my_var[i]);
      }
      @
      Wrote quite quickly without thinking, might contain nuts!

      (Z(:^

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #5

        Another possibility would be:

        @
        my_var[4] = { "Var1", "Var2", "Var3", "Var4"};

        QComboBox *comboBox;
        comboBox = new QComboBox();

        for (i = 0; i < sizeof(my_var); i++) {
        comboBox.addItem(my_var[i]);
        }
        @

        sizeof (array variable) returns the length of the array, if the array is defined as fixed size ;-)

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #6

          [quote author="Gerolf" date="1315157192"]
          sizeof (array variable) returns the length of the array, if the array is defined as fixed size ;-)[/quote]

          Well, yes, it does ;) Was actually thinking about using it, but - strangely - decided not to.

          (Z(:^

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dangelog
            wrote on last edited by
            #7

            [quote author="Gerolf" date="1315157192"]
            sizeof (array variable) returns the length of the array, if the array is defined as fixed size ;-)[/quote]

            No. It returns the size (in "char" units) of the array. sizeof(array)/sizeof(element) is what you want.

            Software Engineer
            KDAB (UK) Ltd., a KDAB Group company

            1 Reply Last reply
            0
            • O Offline
              O Offline
              octal
              wrote on last edited by
              #8

              Gerolf, I think it's a little bit confusing.

              sizeof, as defined by the standard yields the number in bytes of its operand (since it's an unary operator).

              First,

              @
              my_var[4] = { "Var1", "Var2", "Var3", "Var4"};
              @

              lacks a type. This should be :

              @
              const char *arr[] = { "Var1", "Var2", "Var3", "Var4"};
              @

              Then, @sizeof arr@ will yield the total number of bytes for arr representation. It won't give you the length of the array. Thus, if you need the length, you'll need to divide by the size of its element :

              @
              for (std::size_t i = 0; i < sizeof my_var / sizeof *my_var; i++) {
              qDebug() << my_var[i];
              }
              @

              and notice that the result of sizeof is a constant of type std::size_t which is defined in the cstddef header

              1 Reply Last reply
              0
              • R Offline
                R Offline
                RichardM198030
                wrote on last edited by
                #9

                LOL, thanks for all the posts, this is great, =). And now I think it's starting to come back to me now, I did this one a long time ago, but it was just once, so my memory wasn't kept up on it.. I do remember using the

                [code]

                 for (i = 0; i < (my_var); I++) {
                       comboBox->addItem(my_var[i]);
                

                }

                [/code]

                part, and it worked, this is considered solved, =). Some of that other stuff went over my head, hehe.. The const char *arr[] = { }; part, hehehe..

                1 Reply Last reply
                0
                • sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #10

                  octal - true, I've just checked on a live program. Been using QList and such for too long, as it would seem :)

                  (Z(:^

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    RichardM198030
                    wrote on last edited by
                    #11

                    I'm just getting tired of doing Text Editor after Text Editor, which honestly, isn't getting anywhere, I'm trying to improve my Qt Knowledge some, learn different things. Like, because of this loop issue, I was trying to learn how to make a QProgressBar increase in % when you used the QSlider Object, this might be a little more advanced looping feature, or am I wrong? I set ScrollBar as 0% default setting, and 100% at maximum setting. But, I've since deleted that project, just because I wasn't really getting anywhere with it. I type my apps from ground up, surprised I can remember that much, but I can, it's amazing at what we can remember, =P. Eventually I'll have to learn even more features of Qt, it's a pretty good TK, I showed a friend it, and he couldn't believe how much Qt Supports, from C to C++ to Python, he tried to run the old text editor I had, but kept getting errors he said, he thinks it's he Qt installation.. But anyway, thanks for the responses, =).

                    1 Reply Last reply
                    0
                    • O Offline
                      O Offline
                      octal
                      wrote on last edited by
                      #12

                      Yes, Qt is an amazing toolkit, but there is no secret, before using it, you need some basic C++ knowledge.

                      I then suggest you to refresh your memory with some C++ basics before going on :)

                      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