Skip to content
QtWS25 Call for Papers
  • 0 Votes
    4 Posts
    59 Views
    artwawA

    @SGaist Hi, apologies - didn't want to delete and there was no other option...

    EDIT: initial response snippet was unclear! adding more code.

    A small example of values I wanted to put in that loop:

    void PrefsDialog::defaultSection(const int idx) { QSettings settings; settings.beginWriteArray("visual"); settings.setArrayIndex(idx); settings.setValue("override",false); settings.setValue("txtClr",idx==1?"#00F":"#000"); settings.setValue("u",idx==1?true:false); settings.setValue("i",idx==2?true:false); settings.setValue("b",(idx>2&&idx<6)?true:false); settings.setValue("txtBg","#fff"); settings.setValue("ident",idx==2?15:0); settings.endArray(); }
  • 0 Votes
    3 Posts
    51 Views
    C

    @sayan275 said in QLineedit adding extra \ from text():

    qInfo()<<__FUNCTION__<<textentered;

    When you use the QDebug functions the output is in the form of a C++ literal with anything that would need to be escaped inside the double-quotes, escaped. In this case the backslashes, but also any embedded double quote etc.

  • 0 Votes
    6 Posts
    205 Views
    jsulmJ

    @CJha The problem is that you can't just replace something in a file if new value has different lenght than the old one. In this case you need to read the file into memory, replace the value and write it back. To read such an ini file and replace something there Qt needs to know how to interpret the data it reads.

  • 0 Votes
    6 Posts
    274 Views
    SavizS

    @SGaist That is a very good point. I will change it.

  • QSettings and localized key

    Solved General and Desktop
    8
    0 Votes
    8 Posts
    432 Views
    push_backP

    @ChrisW67 That was exactly what I was looking for!
    I am indeed using Qt5, and did not notice that there is QSettings::setIniCodec.
    Thanks a lot!

  • 0 Votes
    6 Posts
    324 Views
    SGaistS

    When you use custom types, it's pretty usual to register them all before building any of the widgets that will use them as part of your application startup sequence after you created your QApplication object.

  • 0 Votes
    9 Posts
    486 Views
    CJhaC

    @JonB Yeah, I was thinking of doing this because there are signals for both applicationDisplayNameChanged() & applicationNameChanged() this can provide me with an application-wide signal to change users. My application has different modules which are completely independent of each other (I have to develop a lot of custom applications where not each application has to have all modules, and so independent modules are the best idea), the common things among these modules are stored directly inside a namespace (every module is also inside this namespace) and so I need an application-level signal to propagate common settings for my application, i.e. current user master key, current font and current palette. For font and palette, QApplication provides the respective ..changed() signal but there is no way for me to add an application-level signal for the master user key without creating a singleton, which I very much want to avoid, that's why I was thinking of using applicationDisplayName as master user key :)

    @JonB @SGaist Thanks for the insight, I will figure out a different way then.

    P.S. It would be nice to have a void QCoreApplication::broadcast(const QString& string) signal, the string could be modified in different ways to provide different values to the broadcast :)

  • 0 Votes
    14 Posts
    989 Views
    R

    I fixed this by setting QFont font = this->font(); to ui->appName->font(); in case anyone comes across this.

  • 0 Votes
    4 Posts
    3k Views
    A

    @jsulm Thanks after reading documentation again, i was able to use QSettings
    For anyone who needs some idea on using config files below code snippet might help you.

    ui->pushButton->setVisible(false); QSettings settings("../config/settings.ini",QSettings::IniFormat); QStringList keys = settings.allKeys(); for (auto i=0;i<keys.size();i++) { configvalues.push_back(settings.value(keys[i]).toString()); } Channel = configvalues[0].toInt() ; auto my_Ip = configvalues[1]; auto hostIp = configvalues[2]; auto iterations = configvalues[3]; Port = configvalues[0].toInt();
  • 0 Votes
    5 Posts
    371 Views
    V

    So that means that the custom 'style' is intentional. That answers my question.

    Thanks for your answer!

  • 0 Votes
    3 Posts
    340 Views
    M

    Qsettings documentation says it is reentrant and thread-safe but since I have started adding .sync() between writing and reading, I have not seen the problem.

  • 0 Votes
    5 Posts
    907 Views
    A

    @jsulm you are right!
    I guess that is my case List files in sub-directories with QDir's filter

  • 0 Votes
    5 Posts
    966 Views
    D
    /home/user/daiajo/.config/Daiajo/Combo.conf

    Found them there.

  • 0 Votes
    16 Posts
    3k Views
    S

    Replying to myself:

    The bugrepport said is is fixed for 5.10.1

    https://bugreports.qt.io/browse/QTBUG-64121

    And it can be made to work with correct folder permissions :

    $ ls -ld /etc/config/ drwxr-xr-x 2 root root 4096 avril 1 11:15 /etc/config/ $ sudo chgrp pi /etc/config/ $ sudo chmod g+w /etc/config/ $ ls -ld /etc/cleandrop/ drwxrwxr-x 2 root pi 4096 avril 1 11:15 /etc/config/

    resolving simlink doesn't helps

    // resolve symlink // https://bugreports.qt.io/browse/QTBUG-64121 QFileInfo info(_configuration_file); if (info.isSymLink()) _configuration_file = info.symLinkTarget();

    So I removed this fix, and fixed the folder permission and it worked.

  • 0 Votes
    2 Posts
    823 Views
    the_T

    @Tusharh
    If you want the value of the registry entry "TaskCache" you should use QSettings::value(QString key) QObject::property(QString name) gives you the property of your QSettings object

  • 0 Votes
    4 Posts
    8k Views
    Q

    I just had a typo in the group ^^
    Sorry!

  • 0 Votes
    3 Posts
    3k Views
    tmladekT

    Hi, thank you for the response!

    Unfortunately, when I try to save a QList<MyStruct>, I get the following error at runtime:

    QVariant::save: unable to save type 'QList<Action>' (type id: 1032). ASSERT failure in QVariant::save: "Invalid type to save", file kernel\qvariant.cpp, line 2124 Invalid parameter passed to C runtime function.

    This is even though I have (after some wrestling) managed to successfully save a Action (MyStruct) using QVariant::fromValue(), having registered both Action as a metatype as well as its operators in main():

    qRegisterMetaType<Action>("Action"); qRegisterMetaTypeStreamOperators<Action>("Action");

    Any idea why that might be?

    edit: A-ha! For future reference, it isn't needed to create custom operators for QList<MyStruct>, but it's still required to call qRegisterMetaTypeStreamOperators() on QList<MyStruct>. Solved!

  • 0 Votes
    2 Posts
    2k Views
    the_T

    @mojito

    As mentioned in the documentation a single "\" or "/" indicates a subkey separator. You could try to use "\\" instead of "\".

  • Qsettings trouble

    Unsolved General and Desktop
    2
    0 Votes
    2 Posts
    643 Views
    Chris KawaC

    Hi, welcome to the forum.

    QSettings operates on QVariant to store/read the data. You need to make your types known to Qt's type system for them to be used as QVariant and they need to have a registered streaming operators to be serialized.
    See these docs for more info: Q_DECLARE_METATYPE, Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE, qRegisterMetaTypeStreamOperators.

    There's also a problem with your last type. Don't save pointers (MyClass*). After your app restart they would point to garbage. Your stream operator for that container should save the actual objects data and recreate the object from that data on load.

  • 0 Votes
    3 Posts
    2k Views
    T

    thanks for your anwser