kImageAnnotator icon indicating copy to clipboard operation
kImageAnnotator copied to clipboard

Save position of dockwidgets regardless of closing the application

Open pominov opened this issue 2 years ago • 9 comments

Make it possible to save the dockwidget positions when the KImageAnnotator is destroyed as subwindow of another application before closing the application

pominov avatar Jun 29 '22 08:06 pominov

I'm not sure if this is goring to work. I think I have tested this options to persist in the destructor but it didn't work that well. I need to do bit of testing on this PR the I'll get back to you.

DamirPorobic avatar Jun 30 '22 19:06 DamirPorobic

Thanks. I don't know why it won't work. I'm tested it too on kImageAnnotator-example and spectacle. I wanted to use the kImageAnnotator in the gwenview as modal dialog and faced with the fact that if I delete it before I close the application - the positions of the widgets are not saved

pominov avatar Jul 01 '22 03:07 pominov

I think the reason "why" it's not working in your case is that the application is Gwenview or Spectacle and you open the kImageAnnotator just as a window and close it without the main loop of qApp still running and not quitting.

Can you try replacing the qApp::aboutToQuit signal with this::destroyed, like this:

connect(this, &QCoreApplication::destroyed, this, &AnnotationWidget::persistDockWidgets);

Without the method call in the destructor.

DamirPorobic avatar Jul 10 '22 18:07 DamirPorobic

It doesn't make sense. Because I'm deleting annotation window and not deleting qApp. Signal QCoreApplication::destroyed will not be emmited. I think destructor is the optimal solution.

pominov avatar Jul 14 '22 11:07 pominov

Sorry, my bad, I meant &AnnotationWidget::destroyed of course as this one is being destroyed.

DamirPorobic avatar Jul 14 '22 11:07 DamirPorobic

Sorry, my bad, I meant &AnnotationWidget::destroyed of course as this one is being destroyed.

In fact this is the call of destructor. No problem, i can change to signal/slot

pominov avatar Jul 14 '22 11:07 pominov

I checked your version with connect. This will crash the program because the signal is emitted in the QObject's destructor when the AnnotationWidget's destructor has already completed and we cannot call its methods. But the call in the destructor of the AnnotationWidget's itself is the norm, because field mConfig is valid until the AnnotationWidget's destructor completes

pominov avatar Aug 02 '22 17:08 pominov

The issue with the destructor is that will only be called with a graceful shutdown, if the application finishes unexpectedly the position would not be saved. That's why it was not in initially in the destructor, it was quit the usualy use case while testing the app. Maybe this is not that big issue.

DamirPorobic avatar Aug 22 '22 05:08 DamirPorobic

if the application terminates unexpectedly, the signal from qApp will also not be sent and processed. In this case, there is a chance to save something only by catching the exception. But that's out of the scope of this issue.

pominov avatar Aug 22 '22 16:08 pominov