Results 1 to 4 of 4

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

Threaded View

Previous Post Previous Post   Next Post Next Post
  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; 5th February 2019 at 23:55.

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, 13:39
  2. Replies: 2
    Last Post: 19th October 2017, 23:25
  3. Variable variable names
    By KeineAhnung in forum Newbie
    Replies: 2
    Last Post: 22nd June 2014, 19:00
  4. Replies: 8
    Last Post: 29th July 2012, 01:28
  5. Replies: 5
    Last Post: 10th May 2012, 06: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.