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. Name an unknown number of widgets with a name followed by an integer
Forum Updated to NodeBB v4.3 + New Features

Name an unknown number of widgets with a name followed by an integer

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 5 Posters 1.4k 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.
  • N N1coc4colA

    Look at the file "mainwindow.cpp", "mainwindow.h" and "mailbutton.*" At the root of the git. I can't past the code now, I havent my pc.
    https://github.com/N1coc4colA/Mails/blob/master/mainwindow.cpp
    Look at the end of the file, in the function "ChilkatSample()"

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #4

    @N1coc4colA

    Hi
    Do you mean the

     int numEmails = bundle->get_MessageCount();
    while (i < numEmails) {
    

    loop `?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      arsinte_andrei
      wrote on last edited by
      #5
      qDebug() << "Opening Mailbox (inbox) was successfull";
      

      is not doing anything - is after return

      mail->setObjectName(magik);
      
      1. this has to be exactly after the creation of the object - is the NAME of the object you created -
      2. you create to many objects with the very same name - names have to be unique
      3. use something like
      mail->setObjectName(magik.append(QString::number(i)));
      

      hope that helped

      1 Reply Last reply
      4
      • N Offline
        N Offline
        N1coc4colA
        wrote on last edited by
        #6

        Yes, but after, to access it with a pointer, I have to use what? magik.append(QString::number(i)))->.... ?

        mrjjM 1 Reply Last reply
        0
        • N N1coc4colA

          Yes, but after, to access it with a pointer, I have to use what? magik.append(QString::number(i)))->.... ?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #7

          @N1coc4colA
          Hi
          That only sets the object name.
          If you need pointers to the widgets, you should keep a list around
          or build one on demand with
          FindChildren.

          1 Reply Last reply
          3
          • N Offline
            N Offline
            N1coc4colA
            wrote on last edited by
            #8

            OK, thank you. I think I'll use the second one, Do a list is hard, prefer the second, due to the unknown number of widgets and the fact that I need to use connect(), it'll be better for me.Thanks for your help, Master of Qt, who's on every chats, I'll maybe ask you for help in the future. ;)

            Pl45m4P 1 Reply Last reply
            0
            • N N1coc4colA

              OK, thank you. I think I'll use the second one, Do a list is hard, prefer the second, due to the unknown number of widgets and the fact that I need to use connect(), it'll be better for me.Thanks for your help, Master of Qt, who's on every chats, I'll maybe ask you for help in the future. ;)

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

              @N1coc4colA said in Name an unknown number of widgets with a name followed by an integer:

              Do a list is hard

              It's not that hard... but you have to ensure, that everything is cleaned up correctly.
              Maybe a vector / list of QSharedPointers.


              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
              • N Offline
                N Offline
                N1coc4colA
                wrote on last edited by
                #10

                connect(this->findChildren<MailButton *>("mail" + QString::number(i)), SIGNAL(Processed(QString)), this, SLOT(MessageFallBack(QString)));
                I can use it, so?

                jsulmJ 1 Reply Last reply
                0
                • N N1coc4colA

                  connect(this->findChildren<MailButton *>("mail" + QString::number(i)), SIGNAL(Processed(QString)), this, SLOT(MessageFallBack(QString)));
                  I can use it, so?

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

                  @N1coc4colA said in Name an unknown number of widgets with a name followed by an integer:

                  I can use it, so?

                  No, this can't work.
                  You have to call connect for every button. You can do this in a loop.

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

                  N 1 Reply Last reply
                  3
                  • jsulmJ jsulm

                    @N1coc4colA said in Name an unknown number of widgets with a name followed by an integer:

                    I can use it, so?

                    No, this can't work.
                    You have to call connect for every button. You can do this in a loop.

                    N Offline
                    N Offline
                    N1coc4colA
                    wrote on last edited by
                    #12

                    @jsulm, I have my loop, all the code is already in a loop. I have a loop of the number of mails, it create the MailButton I talked about. I had to change the name in depending of the no. and to use some pointers and some connect(), now it's fix. You said that I have to put it the loop, so it's right. But, as I said it should work, right?

                    Pl45m4P 1 Reply Last reply
                    0
                    • N N1coc4colA

                      @jsulm, I have my loop, all the code is already in a loop. I have a loop of the number of mails, it create the MailButton I talked about. I had to change the name in depending of the no. and to use some pointers and some connect(), now it's fix. You said that I have to put it the loop, so it's right. But, as I said it should work, right?

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

                      @N1coc4colA

                      You can not loop over this. You have to use an object with an index.

                      For example:

                      QVector <MyButtons*> m_buttons;
                      
                      for (int i = 0; i < 10; i++)
                      {
                          m_buttons.pushback(new MyButton ());
                          connect (m_buttons.at(i), &MyButton::clicked, dest, &MyDestination::DoSomething);
                      }
                      

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

                      ~E. W. Dijkstra

                      N 1 Reply Last reply
                      1
                      • Pl45m4P Pl45m4

                        @N1coc4colA

                        You can not loop over this. You have to use an object with an index.

                        For example:

                        QVector <MyButtons*> m_buttons;
                        
                        for (int i = 0; i < 10; i++)
                        {
                            m_buttons.pushback(new MyButton ());
                            connect (m_buttons.at(i), &MyButton::clicked, dest, &MyDestination::DoSomething);
                        }
                        
                        N Offline
                        N Offline
                        N1coc4colA
                        wrote on last edited by
                        #14

                        OK, thank you for the answer

                        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