Results 1 to 4 of 4

Thread: Application reverts to old stored variable instead of the updated variable

  1. #1
    Join Date
    Feb 2019
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Application reverts to old stored variable instead of the updated variable

    Hello,

    I am working on a project where a user selects a theme option. When the app reloads it should display the new theme. Currently, the program launches by searching the QSettings through a OptionsModel.cpp class looking for variables stored. If not stored, it returns the default variable. The UI's are then loaded and pull from this code to grab the correct theme.
    Qt Code:
    1. QString loadStyleSheet()
    2. {
    3. QString styleSheet;
    4. QSettings settings;
    5. QString cssName;
    6. QString theme = settings.value("theme", "").toString();
    7. if(!theme.isEmpty()){
    8. cssName = QString(":/css/") + theme;
    9. }
    10.  
    11. else {
    12. cssName = QString(":/css/light");
    13. settings.setValue("theme", "light");
    14. }
    15.  
    16. QFile qFile(cssName);
    17. if (qFile.open(QFile::ReadOnly)) {
    18. styleSheet = QLatin1String(qFile.readAll());
    19. }
    20.  
    21. return styleSheet;
    22. }
    To copy to clipboard, switch view to plain text mode 

    The correct UI css should be loaded. If someone wants to change the theme they navigate to the options dialog and select the dark option from the dropdown menu. This is mapped as a change and stored into the theme variable with settings.setValue("theme", theme). using GUIUtil::getThemeName which is very similar to the above code but for the theme variable instead. Through debugging I have been able to successfully print the theme variable as dark. I ran settings.sync() to store the variable and update the setting storage. When I restart the application to launch the dark theme, the light theme variable remains in the Qsettings. Additionally, if I set the default variable of the code above to dark, ie if there was nothing being stored in settings it should go with the dark theme, it doesn't go with the dark theme and again reverts to the light theme.


    I'm building on Ubuntu 16.04 and I have no build errors. I know I'm not giving y'all a lot of information on the problem, but I hoped to give enough that if someone had any ideas as to why the wrong variable is being stored they would be able to help.

    Thank You in advance
    Last edited by QT-wannabe; 6th February 2019 at 00:55.

  2. #2
    Join Date
    Feb 2019
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Application reverts to old stored variable instead of the updated variable

    Hello,

    I am working on a project where a user selects a theme option. When the app reloads it should display the new theme. Currently, the program launches by searching the QSettings through a OptionsModel.cpp class looking for variables stored. If not stored, it returns the default variable. The UI's are then loaded and pull from this code to grab the correct theme.
    Qt Code:
    1. QString loadStyleSheet()
    2. {
    3. QString styleSheet;
    4. QSettings settings;
    5. QString cssName;
    6. QString theme = settings.value("theme", "").toString();
    7. if(!theme.isEmpty()){
    8. cssName = QString(":/css/") + theme;
    9. }
    10.  
    11. else {
    12. cssName = QString(":/css/light");
    13. settings.setValue("theme", "light");
    14. }
    15.  
    16. QFile qFile(cssName);
    17. if (qFile.open(QFile::ReadOnly)) {
    18. styleSheet = QLatin1String(qFile.readAll());
    19. }
    20.  
    21. return styleSheet;
    22. }
    To copy to clipboard, switch view to plain text mode 

    The correct UI css should be loaded. If someone wants to change the theme they navigate to the options dialog and select the dark option from the dropdown menu. This is mapped as a change and stored into the theme variable with settings.setValue("theme", theme). using GUIUtil::getThemeName which is very similar to the above code but for the theme variable instead. Through debugging I have been able to successfully print the theme variable as dark. I ran settings.sync() to store the variable and update the setting storage. When I restart the application to launch the dark theme, the light theme variable remains in the Qsettings. Additionally, if I set the default variable of the code above to dark, ie if there was nothing being stored in settings it should go with the dark theme, it doesn't go with the dark theme and again reverts to the light theme.


    I'm building on Ubuntu 16.04 and I have no build errors. I know I'm not giving y'all a lot of information on the problem, but I hoped to give enough that if someone had any ideas as to why the wrong variable is being stored they would be able to help.

    Thank You in advance

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Application reverts to old stored variable instead of the updated variable

    Have you checked the INI file after changing the theme?
    Does it contain the correct value?

    Cheers,
    _

  4. #4
    Join Date
    Feb 2019
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Application reverts to old stored variable instead of the updated variable

    Quote Originally Posted by anda_skoa View Post
    Have you checked the INI file after changing the theme?
    Does it contain the correct value?

    Cheers,
    _
    The file remains light although my debugs are saying that settings.value("theme", "") is dark. Besides settings.setValue is there another way to write to the INI file? I have noticed that before I started trying to change the theme that I could change the language and have it saved to the INI. I must have broken the save mechanism somehow?


    Added after 1 30 minutes:


    Turns out I did indeed delete something I wasn't suppose to. Starting over everything builds and saves perfectly.
    Last edited by QT-wannabe; 6th February 2019 at 20:37.

Similar Threads

  1. How to show the value of stored session variable in MySQL from qt?
    By Ahmed Abdellatif in forum Qt Programming
    Replies: 0
    Last Post: 5th May 2018, 14:39
  2. Replies: 2
    Last Post: 20th October 2017, 00:25
  3. Variable variable names
    By KeineAhnung in forum Newbie
    Replies: 2
    Last Post: 22nd June 2014, 20:00
  4. Replies: 8
    Last Post: 29th July 2012, 02:28
  5. Replies: 5
    Last Post: 10th May 2012, 07:22

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.