English 中文(简体)
QSettings: Move / change the scope / place of an existing QSettings 目的
原标题:QSettings: Move / change the scope / location of an existing QSettings Object

我正在撰写一个节目,在QSettings物体中储存所有环境。 现在我要让用户选择改变其数据储存地点。 申请资格并不能改变其范围,将其全部数据复制到一个新的地点,从登记处到档案中所占百分比是APPDATA%。

我知道:

  • QSettings::setPath() is used before construction and doesn t affect existing objects.
  • The copy operator is private. I could subclass QSettings but I am afraid of settings being lost during the copy operation because of other threads writing simultaneously.

我如何把我的节目环境移至一个新的地点? 如果有可能,我真的希望能以重新安置的方式做到这一点。

问题回答

read-安全单带包装类别是否是一种选择?

class Settings {

public:
    static Settings& instance() 
    { 
        static Settings* inst = 0;
        if (!inst)
            inst = new Settings();
        return *inst; 
    }
    QSettings& getSettings { QMutexLocker(&m_mutex); return *m_settings; }
    bool migrateLocation(...) 
    { 
        QMutexLocker(&m_mutex); 
        QSettings* newSettings = new QSettings(...new parameters...);
        //... copy over the stuff
        delete m_settings;
        m_settings = newSettings;
    }
private:
    Settings() { m_settings = new QSettings(...); }

    static QMutex m_mutex;
    QSettings* m_settings;
}




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签