Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Child QWidget QSettings crash
Forum Updated to NodeBB v4.3 + New Features

Child QWidget QSettings crash

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 308 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by sonichy
    #1

    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())
    {
    
    }
    

    https://github.com/sonichy

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      sonichyS 1 Reply Last reply
      2
      • SGaistS SGaist

        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.

        sonichyS Offline
        sonichyS Offline
        sonichy
        wrote on last edited by sonichy
        #3

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

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

        https://github.com/sonichy

        JonBJ 1 Reply Last reply
        0
        • sonichyS sonichy

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

          DatetimeWidget::DatetimeWidget(QWidget *parent) : QWidget(parent)
          {
              QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
          }
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @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....

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved