so ich habe jetzt herausgefunden, dass ich mit QSettings arbeiten muss. Ich habe mir bereits eine NSettings angelegt.
NSettings.cpp
Code: Alles auswählen
#include "NSettings.h"
#include <QDebug>
NSettings :: NSettings(const QString & fileName, QObject * parent):
QSettings(fileName, QSettings::IniFormat){
setFallbacksEnabled(false);
}
NSettings::~NSettings() {
sync();
}
double NSettings::readDouble(const QString & key){
return value(key).toDouble();
}
und die NSettings.h
Code: Alles auswählen
#ifndef NSETTINGS_H
#define NSETTINGS_H
#include <QSettings>
class NSettings : public QSettings {
Q_OBJECT
public:
NSettings(const QString &, QObject * = 0);
virtual ~NSettings();
virtual double readDouble(const QString &);
private:
NSettings(const NSettings &);
NSettings & operator=(const NSettings &);
};
#endif
includiert habe ich sie in der TabZwei.cpp
Code: Alles auswählen
#include <QtGui>
#include "TabZwei.h"
#include "NSettings.h"
#include "NSettings.h"
TabZwei::TabZwei(QWidget *parent)
:QWidget(parent)
{
setupUi(this);
connect(loadFilePB, SIGNAL(clicked()),
this, SLOT(open()));
connect(saveDataPB, SIGNAL(clicked()),
this, SLOT(saveData()));
_list << "C1" << "C3" << "C5" << "C7" << "B2x" << "B2y" << "B4x" << "B4y" << "B6x" << "B6y"
<< "S3x" << "S3y" << "S5x" << "S5y" << "S7x" << "S7y" << "D4x" << "D4y" << "D6x" << "D6y"
<< "R5x" << "R5y" << "R7x" << "R7y" << "F6x" << "F6y" << "G7x" << "G7y" << "A1x" << "A1y"
<< "A2x" << "A2y" << "A3x" << "A3y" << "A4x" << "A4y" << "A5x" << "A5y" << "A6x" << "A6y" << "A7x" << "A7y";
_hash.insert("C1", doubleSpinBox_C1);
_hash.insert("C3", doubleSpinBox_C3);
_hash.insert("C5", doubleSpinBox_C5);
_hash.insert("C7", doubleSpinBox_C7);
_hash.insert("B2x", doubleSpinBox_B2x), _hash.insert("B2y", doubleSpinBox_B2y);
_hash.insert("B4x", doubleSpinBox_B4x), _hash.insert("B4y", doubleSpinBox_B4y);
_hash.insert("B6x", doubleSpinBox_B6x), _hash.insert("B6y", doubleSpinBox_B6y);
_hash.insert("S3x", doubleSpinBox_S3x), _hash.insert("S3y", doubleSpinBox_S3y);
_hash.insert("S5x", doubleSpinBox_S5x), _hash.insert("S5y", doubleSpinBox_S5y);
_hash.insert("S7x", doubleSpinBox_S7x), _hash.insert("S7y", doubleSpinBox_S7y);
_hash.insert("D4x", doubleSpinBox_D4x), _hash.insert("D4y", doubleSpinBox_D4y);
_hash.insert("D6x", doubleSpinBox_D6x), _hash.insert("D6y", doubleSpinBox_D6y);
_hash.insert("R5x", doubleSpinBox_R5x), _hash.insert("R5y", doubleSpinBox_R5y);
_hash.insert("R7x", doubleSpinBox_R7x), _hash.insert("R7y", doubleSpinBox_R7y);
_hash.insert("F6x", doubleSpinBox_F6x), _hash.insert("F6y", doubleSpinBox_F6y);
_hash.insert("G7x", doubleSpinBox_G7x), _hash.insert("G7y", doubleSpinBox_G7y);
_hash.insert("A1x", doubleSpinBox_A1x), _hash.insert("A1y", doubleSpinBox_A1y);
_hash.insert("A2x", doubleSpinBox_A2x), _hash.insert("A2y", doubleSpinBox_A2y);
_hash.insert("A3x", doubleSpinBox_A3x), _hash.insert("A3y", doubleSpinBox_A3y);
_hash.insert("A4x", doubleSpinBox_A4x), _hash.insert("A4y", doubleSpinBox_A4y);
_hash.insert("A5x", doubleSpinBox_A5x), _hash.insert("A5y", doubleSpinBox_A5y);
_hash.insert("A6x", doubleSpinBox_A6x), _hash.insert("A6y", doubleSpinBox_A6y);
_hash.insert("A7x", doubleSpinBox_A7x), _hash.insert("A7y", doubleSpinBox_A7y);
}
void TabZwei::open(){
//filedialog
//QString fileName
//NSettings n(fileName,this);
//_hash.value("C1")->setValue(n.readDouble("C1"));
QString fileName = QFileDialog::getOpenFileName(this, "Open File", "/home", ("Datei(*.ini *.txt *.dat *.odt)"));
NSettings n(fileName, this);
for(double i = 0; i < _list.size(); ++i){
_hash.value(i)->setValue(n.readDouble(i));
}
}
void TabZwei::saveData(){
//
double d;
d = (_hash.value("C1"))->value();
qDebug() << d;
d++;
_hash.value("C1")->setValue(d);
Jetzt kommt eine Fehlermeldung, die ich zwar verstehe (naja die eine zumidest) aber nicht weiss, wie ich ihn beheben soll.
Fehlermeldung
Code: Alles auswählen
TabZwei.cpp: In member function 'void TabZwei::open()':
TabZwei.cpp:70: error: no matching function for call to 'QHash<QString, QDoubleSpinBox*>::value(double&)'
/usr/include/qt4/QtCore/qhash.h:544: note: candidates are: const T QHash<Key, T>::value(const Key&) const [with Key = QString, T = QDoubleSpinBox*]
/usr/include/qt4/QtCore/qhash.h:555: note: const T QHash<Key, T>::value(const Key&, const T&) const [with Key = QString, T = QDoubleSpinBox*]
TabZwei.cpp:70: error: no matching function for call to 'NSettings::readDouble(double&)'
NSettings.h:13: note: candidates are: virtual double NSettings::readDouble(const QString&, const double&)
make: *** [TabZwei.o] Fehler 1
vlt habt ihr auch noch Verbesserungsvorschläge für mich, das ganze übersichtlicher zu machen und kürzer ^^, danke.
lg
nici