Name an unknown number of widgets with a name followed by an integer
-
sorry for my ignorance but after I had a look into your git I couldn't find the code that you speaking about... can you post it here, please. and let us know when you get the error on the creation or when you use it??
-
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()" -
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()"Hi
Do you mean theint numEmails = bundle->get_MessageCount(); while (i < numEmails) {
loop `?
-
qDebug() << "Opening Mailbox (inbox) was successfull";
is not doing anything - is after return
mail->setObjectName(magik);
- this has to be exactly after the creation of the object - is the NAME of the object you created -
- you create to many objects with the very same name - names have to be unique
- use something like
mail->setObjectName(magik.append(QString::number(i)));
hope that helped
-
Yes, but after, to access it with a pointer, I have to use what? magik.append(QString::number(i)))->.... ?
-
Yes, but after, to access it with a pointer, I have to use what? magik.append(QString::number(i)))->.... ?
@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. -
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. ;)
-
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. ;)
@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. -
connect(this->findChildren<MailButton *>("mail" + QString::number(i)), SIGNAL(Processed(QString)), this, SLOT(MessageFallBack(QString)));
I can use it, so? -
connect(this->findChildren<MailButton *>("mail" + QString::number(i)), SIGNAL(Processed(QString)), this, SLOT(MessageFallBack(QString)));
I can use it, so?@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. -
@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.@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?
-
@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?
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); }
-
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); }
OK, thank you for the answer