Subclassing QSettings give error on the position of ini file in Linux Kubuntu
-
the problem is that I've made a subclass of the QSettings and I can not set a proper path for the ini file. the app have to work on windows and linux maybe mac but after few years.. not now...
- AtpSettings - the subclassing class
@
AtpSettings::AtpSettings(QString iniFileName) {
QString iniFileNameAndPath;
iniFileNameAndPath = AtpSettings::getApplicationPath() + "/" + iniFileName;
qDebug() << iniFileNameAndPath;
mySettings->setPath(Format::IniFormat, Scope::UserScope, AtpSettings::getApplicationPath());
mySettings = new QSettings(iniFileNameAndPath ,QSettings::IniFormat);
mySettings->setDefaultFormat(QSettings::IniFormat);
mySettings->setFallbacksEnabled(false);
}AtpSettings::~AtpSettings(){
qDebug() <<"Exit AtpSettings";
}QPoint AtpSettings::getAppPosition(){
return mySettings->value("Appearance/Position", QPoint(500, 700)).toPoint();
}void AtpSettings::setAppPosition(QPoint pointsPos){
mySettings->setValue("Appearance/Position", pointsPos);
qDebug() << mySettings->fileName();
}QSize AtpSettings::getAppSize(){
return mySettings->value("Appearance/Size", QSize(1000, 800)).toSize();
}void AtpSettings::setAppSize(QSize appSize){
mySettings->setValue("Appearance/Size", appSize);
qDebug() << mySettings->fileName();
}QString AtpSettings::getApplicationPath() {
QDir dirName(QApplication::applicationDirPath());
qDebug() << dirName.path();
return dirName.path();
}
@- AtpMainWindow
@
AtpMainWindow::AtpMainWindow(QWidget *parent, bool hasMdiArea) : QMainWindow(parent){
qDebug()<<"Start AtpMainWindow" << hasMdiArea;
settingsMainWindow = new AtpSettings();
qDebug() << settingsMainWindow->fileName();
setWindowTitle("@atp@");
AtpSingleApplication singleApp = dynamic_cast<AtpSingleApplication> (qApp);
if (singleApp!=NULL) {
singleApp->setActivationWindow(this);
}
readSettings();
}AtpMainWindow::~AtpMainWindow(){
qDebug()<<"Exit AtpMainWindow";
}void AtpMainWindow::quit() {
emit closeRequested();
QMainWindow::close();
}//event on close mainWindow
void AtpMainWindow::closeEvent(QCloseEvent *e) {
qDebug()<<"Start closeEvent";
if (maybeSave()) {
writeSettings();
e->accept();
QApplication::quit();
} else {
e->ignore();
}
}//save any unsaved data
bool AtpMainWindow::maybeSave(){
return true;
}//Restores the application window settings (size, position, ...).
void AtpMainWindow::readSettings() {
qDebug()<<"readSettings";
qDebug() << settingsMainWindow->fileName();
QPoint windowPos = settingsMainWindow->getAppPosition();
QSize windowSize = settingsMainWindow->getAppSize();
resize(windowSize);
move(windowPos);
}// Stores the application window settings (size, position, ...).
void AtpMainWindow::writeSettings() {
qDebug()<<"writeSettings";
qDebug() << settingsMainWindow->fileName();
settingsMainWindow->setAppPosition(pos());
settingsMainWindow->setAppSize(size());
qDebug() << settingsMainWindow->fileName();
}
@now in AtpSettings eveything is ok.. all the paths read fine and are corectly displayed by qDebug() << but on AtpMainWindow the output is different on the qDebug()<<. In @AtpMainWindow::AtpMainWindow(QWidget *parent, bool hasMdiArea) : QMainWindow(parent)@ is okit put the ini next to the exe file or executable file in linux, but on the @void AtpMainWindow::readSettings() @ and @void AtpMainWindow::writeSettings() @ it display a different path and i do not change the path anywhere as you can see.
- AtpMainWindow.h
@private:
AtpSettings settingsMainWindow;@
and this is the output on console
@[../../../electricity/src/AtpCore/AtpSettings.cpp:69, static QString AtpSettings::getApplicationPath()]
Debug: "/home/andrei/Qt-projects/electricity/debug"
[../../../electricity/src/AtpCore/AtpSettings.cpp:15, AtpSettings::AtpSettings(QString)]
Debug: "/home/andrei/Qt-projects/electricity/debug/atp.ini"
[../../../electricity/src/AtpCore/AtpSettings.cpp:69, static QString AtpSettings::getApplicationPath()]
Debug: "/home/andrei/Qt-projects/electricity/debug"
[../../../electricity/src/AtpCore/AtpSettings.cpp:69, static QString AtpSettings::getApplicationPath()]
Debug: "/home/andrei/Qt-projects/electricity/debug"
[../../../electricity/src/AtpCore/AtpSettings.cpp:15, AtpSettings::AtpSettings(QString)]
Debug: "/home/andrei/Qt-projects/electricity/debug/atp.ini"
[../../../electricity/src/AtpCore/AtpSettings.cpp:69, static QString AtpSettings::getApplicationPath()]
Debug: "/home/andrei/Qt-projects/electricity/debug"
[../../../electricity/src/AtpGui/AtpMainWindow.cpp:14, AtpMainWindow::AtpMainWindow(QWidget, bool)]
Debug: "/home/andrei/Qt-projects/electricity/debug/atp/@atp@.ini"
[../../../electricity/src/AtpGui/AtpMainWindow.cpp:52, void AtpMainWindow::readSettings()]
Debug: readSettings
[../../../electricity/src/AtpGui/AtpMainWindow.cpp:53, void AtpMainWindow::readSettings()]
Debug: "/home/andrei/Qt-projects/electricity/debug/atp/@atp@.ini"
[../../../electricity/src/AtpGui/AtpMainWindow.cpp:62, void AtpMainWindow::writeSettings()]
Debug: writeSettings
[../../../electricity/src/AtpGui/AtpMainWindow.cpp:63, void AtpMainWindow::writeSettings()]
Debug: "/home/andrei/Qt-projects/electricity/debug/atp/@atp@.ini"
[../../../electricity/src/AtpCore/AtpSettings.cpp:37, void AtpSettings::setAppPosition(QPoint)]
Debug: "/home/andrei/Qt-projects/electricity/debug/atp.ini"
[../../../electricity/src/AtpCore/AtpSettings.cpp:46, void AtpSettings::setAppSize(QSize)]
Debug: "/home/andrei/Qt-projects/electricity/debug/atp.ini"
[../../../electricity/src/AtpGui/AtpMainWindow.cpp:66, void AtpMainWindow::writeSettings()]
Debug: "/home/andrei/Qt-projects/electricity/debug/atp/@atp@.ini" @
is true I have declared this in - main.cpp
@app->setOrganizationName("atp");
app->setOrganizationDomain("atp-trading.com");
app->setApplicationName("@atp@");
app->setApplicationVersion("1");
app->setApplicationDisplayName("atp");@
but i do not understand why is changing the path?? where??
- AtpSettings - the subclassing class
-
Hi,
@
mySettings->setPath(Format::IniFormat, Scope::UserScope, AtpSettings::getApplicationPath());
mySettings = new QSettings(iniFileNameAndPath ,QSettings::IniFormat);
@You are overwriting mySettings. Just out of curiosity, why are you subclassing QSettings ? It doesn't seem that you really need it.
-
just because i'm saving some specific dataand I want to have a file that is dealing with setting all settings - they are in different files but only one main class deal with settings and that is AtpSettings