Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

QSettings for Qt 4.7 TI embedded issue

$
0
0
Hi there! So my problem is that sometimes when i write value to qsettings then tries to get it later, it seems like the value wasn’t saved. This seems to happen pretty randomly. Some background: I use three different application. Each application reads from the same qsetting file, but with different groups, every second. The applications communicates with each other using qsettings by changing each other values for their representive group. However sometimes it seems like when I write from one application, the other application doesn’t get the correct value (or it’s not written at all). I’m using the following shared code between the three applications: template <class T> const T getSharedResources(const QString group, const QString key) {  QSettings settings(QSettings::NativeFormat,QSettings::UserScope ,"Company", "sharedResources");  sync();  settings.sync();  settings.beginGroup(group);  T value;  if(settings.contains(key)) {   value = settings.value(key).value<T>();  }  settings.endGroup();  qDebug() << __FUNCTION__ << group << " " << key  << " " << value;  return value; }   template <class T> void setSharedResources(const QString group, const QString key, const T value) {  qDebug() << __FUNCTION__ << group << " " << key << " " << value;  QSettings settings(QSettings::NativeFormat,QSettings::UserScope ,"Company", "sharedResources");  settings.beginGroup(group);  settings.setValue(key,value);  settings.endGroup();  settings.sync();  sync();  qDebug() << __FUNCTION__ << settings.status() << getSharedResources<T>(group,key); } At the end of setting the qsettings I double check what value was written by using the getsharedresources method. The output goes like this: >> setSharedResources “Slot” “Application1” 2 >> setSharedResources 0 2 >> getSharedResources “Slot” “Application1” 1 How come it changed from output line 2 to line 3? setSharedResources is not called between those lines? Also this is not a bug which happens always, maybe 50/50. What could the problem be? Let me know if something is unclear / Alex

Viewing all articles
Browse latest Browse all 13965

Trending Articles