Using QSettings with QColor



  • Hello everyone,

    I am currently trying to get a saveSettings() and loadSettings() function to work in order to save the settings even when the program is closed. However, I am facing a problem with my loadSettings() function...

    void Settings::saveSettings()
    {
        QSettings setting("textFinder","tFSettings");
    
        setting.beginGroup("textFinder");
        setting.setValue("colour", this->colour); //QColor
        setting.setValue("language", this->language); //QString
        setting.endGroup();
    }
    

    This is the saveSettings() function, and it seems to work without any problems. This is my loadSettings function:

    void textFinder::loadSettings()
    {
        QSettings setting("textFinder","tFSettings");
    
        setting.beginGroup("textFinder");
        defaultColour = setting.value("colour", Qt::yellow);
        defaultLanguage = setting.value("language", "English").toString();
        setting.endGroup();
    }
    

    However, on attempting to compile the program I get the following error:

    C:\Users\Laurenz\Documents\QT\textFinder\textfinder.cpp:131: error: use of deleted function 'QVariant::QVariant(Qt::GlobalColor)

    I get what this error means. I suppose that I have to use something similar to .toString(), but I browsed the list of suggestions and nothing popped up that I could use here... Any suggestions?

    EDIT: Actually, I think I've fixed it. I've basically just created a QString instead and then used the QColor::setNamedColor() to get the colour. Thanks anyways to everyone who read this!



  • @El3ctroGh0st great you have solved the issue. If so, please don't forget to mark your post as such. Thanks.



  • try:

    QColor color=settings.value("colour").value<QColor>();
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.