Child QWidget QSettings crash
Solved
General and Desktop
-
SIGSEGV crash at qobject.h line 324:
type, types, &SignalType::Object::staticMetaObject);//main.cpp int main(int argc, char *argv[]) { QApplication a(argc, argv); a.setOrganizationName("HTY"); a.setApplicationName("HTYDock"); MainWindow w; w.show(); return a.exec(); } //mainwindow.cpp QMainWindow { DatetimeWidget *datetimeWidget = new DatetimeWidget; } //datetimewidget.h { private: enum { TEXT_CLOCK, DIGITAL_CLOCK, ANALOG_CLOCK } clock_type; QSettings settings; // add this line cause crash } //datetimewidget.cpp DatetimeWidget::DatetimeWidget(QWidget *parent) : QWidget(parent) ,settings(QCoreApplication::organizationName(), QCoreApplication::applicationName()) { }
-
Hi,
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.
-
-
@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 evenstatic
. 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....