setFloating method isn't working
-
wrote on 9 Jul 2021, 15:23 last edited by
Hello everyone, hope all is well! In regards to my last post (https://forum.qt.io/topic/128370/when-a-dock-widget-is-floating-how-to-reset-it-back-to-its-initial-area-when-a-button-is-pressed), I thought I was about to reach a solution:
void MainWindow::on_actiont2_triggered() { for (int i = 0; i <= dockCount; i++) { if (dockVector[i]->isFloating()) { dockVector[i]->setFloating(false); // not working } } }
My goal for this function is to place a floating dockWidget back into its starting dock widget area. However, when the button is triggered, the program crashes. After doing some testing and debugging, I realize that the setFloating method is causing this problem. What needs to be done to fix this?
-
Hello everyone, hope all is well! In regards to my last post (https://forum.qt.io/topic/128370/when-a-dock-widget-is-floating-how-to-reset-it-back-to-its-initial-area-when-a-button-is-pressed), I thought I was about to reach a solution:
void MainWindow::on_actiont2_triggered() { for (int i = 0; i <= dockCount; i++) { if (dockVector[i]->isFloating()) { dockVector[i]->setFloating(false); // not working } } }
My goal for this function is to place a floating dockWidget back into its starting dock widget area. However, when the button is triggered, the program crashes. After doing some testing and debugging, I realize that the setFloating method is causing this problem. What needs to be done to fix this?
wrote on 9 Jul 2021, 19:01 last edited by@WesLow said in setFloating method isn't working:
the program crashes
dockVector[i]->setFloating(false); // not working
for (int i = 0; i <= dockCount; i++)
Given the normal ranges one expects in C/C++ coding, are you sure your loop termination condition is correct here?
-
@WesLow said in setFloating method isn't working:
the program crashes
dockVector[i]->setFloating(false); // not working
for (int i = 0; i <= dockCount; i++)
Given the normal ranges one expects in C/C++ coding, are you sure your loop termination condition is correct here?
wrote on 9 Jul 2021, 23:25 last edited by@JonB Thank you for your response. I'm moving over from Java so this might be a problem I run into. What do you mean by normal ranges one expects?
-
@WesLow said in setFloating method isn't working:
the program crashes
dockVector[i]->setFloating(false); // not working
for (int i = 0; i <= dockCount; i++)
Given the normal ranges one expects in C/C++ coding, are you sure your loop termination condition is correct here?
wrote on 9 Jul 2021, 23:37 last edited by@JonB Thank you very much; your advice helped me fix this problem!
-
@JonB Thank you very much; your advice helped me fix this problem!
wrote on 10 Jul 2021, 07:03 last edited by@WesLow
I wanted you to look at the loop and see for yourself what was wrong! Even in Java I believe array indexing/loop counters range from 0 to length-1, it has become in most languages.
1/5