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. Not receiving signal emitted by class derived from QSettings

Not receiving signal emitted by class derived from QSettings

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 517 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.
  • D Offline
    D Offline
    dirtshell
    wrote on last edited by dirtshell
    #1

    I wrote a class called SettingsManager that is derived from QSettings so that when a setting is changed I can trigger a slot in another class (that is related to the setting) that verifies the new setting value is valid. In my derived class I have re-implemented setValue() so that it emits a settingChanged() signal. I am able to succesfully connect the slot and the signal. When I change a setting, SettingsManager::setValue() is called (as verified by a print statement), and the underlying QSettings object is properly updated, but it seems that the signal is either not emitted or the slot does not receive it.

    Here is the SettingsManager class:

    class SettingsManager : public QSettings
    {
    
    Q_OBJECT
    
    public:
        SettingsManager() : QSettings() {}
    
        void remove(const QString &key) {
            QSettings::remove(key);
            emit settingRemoved(key);
        }
    
        void setValue(const QString &key, const QVariant &value) {
            std::cout << "SettingsManager: setting the value for " << key.toStdString() << "\n";  // this is called
            QSettings::setValue(key, value);
            emit settingChanged(key);
        }
    
        void sync() {
            QSettings::sync();
            emit settingsSynced();
        }
    signals:
        void settingRemoved(QString key);
        void settingChanged(QString key);
        void settingsSynced();
    };
    

    I connect to it with the following code in another class, which is in the same thread. Note that s_ is an instance of SettingsManager.

    bool q_settings_connect = connect(&s_, &SettingsManager::settingChanged,
                this, &TopicHandler::UpdateSetting);
    std::cout << "result = " << q_settings_connect << "\n"; // returns "result = 1"
    

    But when I change a setting, TopicHandler::UpdateSetting() is not called. Am I making some kind of fundamental misunderstanding? Or should this work? I will note that the instance of SettingsManager being edited is different from the instance being referenced in the connect() function (as in each class has their own reference to a SettingsManager object), but I assumed that wouldn't matter since I thought it was a singleton.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dirtshell
      wrote on last edited by
      #2

      ALright, upon review and some testing, it turns out that QSettings is not a singleton, so the SettingsManager I am connecting to is not the same instance that is actually being modified.

      1 Reply Last reply
      1
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by
        #3

        so you can mark as solved?

        The dystopian literature that served as a warning in my youth has become an instruction manual in my elder years.

        1 Reply Last reply
        2

        • Login

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