Qt World Summit: Submit your Presentation

Child QWidget QSettings crash

  • SIGSEGV crash at qobject.h line 324:
    type, types, &SignalType::Object::staticMetaObject);

    int main(int argc, char *argv[])
        QApplication a(argc, argv);
        MainWindow w;
        return a.exec();
        DatetimeWidget *datetimeWidget = new DatetimeWidget;
        enum {
        } clock_type;
        QSettings settings;    // add this line cause crash
    DatetimeWidget::DatetimeWidget(QWidget *parent) : QWidget(parent)
       ,settings(QCoreApplication::organizationName(), QCoreApplication::applicationName())

  • Lifetime Qt Champion


    Based on your incomplete header file, it seems that you are creating a static QSettings object. Don't do that.

    In any case, there's no need to have a class member for QSettings. You should create the object when needed.

  • @SGaist It seems child QWidget can not use static QSettings.

    DatetimeWidget::DatetimeWidget(QWidget *parent) : QWidget(parent)
        QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());

  • @sonichy said in Child QWidget QSettings crash:

    It seems child QWidget can not use static QSettings.

    What do you mean? Your code shows getting a QSettings object for your application, no more than that. It's not even static. The fact that you have put the code you show inside a widget is neither here nor there. If something goes wrong with what you have written, you have to say so/what....

Log in to reply