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. Using QSettings with QColor
QtWS25 Last Chance

Using QSettings with QColor

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 2.1k Views
  • 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.
  • E Offline
    E Offline
    El3ctroGh0st
    wrote on last edited by El3ctroGh0st
    #1

    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!

    1 Reply Last reply
    1
    • Pablo J. RoginaP Offline
      Pablo J. RoginaP Offline
      Pablo J. Rogina
      wrote on last edited by
      #2

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

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1
      • M Offline
        M Offline
        mpergand
        wrote on last edited by
        #3

        try:

        QColor color=settings.value("colour").value<QColor>();
        
        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