0

I have a larger application and I want to create GUI dialog for one specific subtask. I decided to use Qt but I am not familiar with it so I am doing this thing probably the wrong way.

My quick and dirty prototype:

void ManualFeatureMatcher::matchFeatures() {
    int argc = 0;
    char* argv[1] = {NULL};
    QApplication a(argc, argv);
    Widget w;
    w.show();
    a.exec();
}

This works fine the first time the function is called but when I call it again I get these errors:

    (app:8540): Gtk-CRITICAL **: IA__gtk_widget_realize: assertion `GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed

    (app:8540): Gtk-CRITICAL **: IA__gtk_widget_realize: assertion `GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed

    (app:8540): Gtk-CRITICAL **: IA__gtk_container_add: assertion `GTK_IS_CONTAINER (container)' failed

    (app:8540): Gtk-CRITICAL **: IA__gtk_widget_realize: assertion `GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed

What is the correct way of accomplishing this?

László Papp
  • 51,870
  • 39
  • 111
  • 135
Honza Brabec
  • 37,388
  • 4
  • 22
  • 30
  • You don't need another QApplication instance, just create your dialog and show it. Modal dialogs contain its own event loop inside. – Archie Oct 19 '13 at 16:34
  • Nesting multiple QApplications are not supported - I also can't think of a reason why you should need that. – Frank Osterfeld Oct 19 '13 at 16:37
  • I don't have any other QApplication instance at the time this method is called. At the moment nothing else except this method in my application knows anything about qt. – Honza Brabec Oct 19 '13 at 16:38
  • Ah, I see. Then your question title is misleading though. – Frank Osterfeld Oct 19 '13 at 16:40
  • QApplication instance is usually created in your main() function. Or are you trying to spawn Qt in a non-Qt application?.. – Archie Oct 19 '13 at 16:43

1 Answers1

1

Solved.

I have made smart pointer to QApplication a member of the class and made sure it is created only once.

Instead of pure Widgets i use QDialogs now so I do not need to run the QApplication loop because as @Archie said in the comment: Modal dialogs contain its own loop inside.

More details on blog

Honza Brabec
  • 37,388
  • 4
  • 22
  • 30