You are not logged in.

1

Thursday, August 8th 2013, 9:58am

Stuck with QSettings [solved]

Hi all,

creating an application for compiling livecd modules, I am trying to replace a startup configuration window with reading settings from a file.
The application is working already but I am stuck with the part mentioned above.
As this is the first time I am using this function, there must be some noobish mistakes...

The values I am trying to read from the config have to be available for all widgets in the application.
If the config does not exist the default values should be used.

error messages while compiling:

Quoted

g++ -c -pipe -Os -march=i486 -mtune=i686 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/lib/qt/mkspecs/linux-g++ -I. -I/usr/lib/qt/include/QtCore -I/usr/lib/qt/include/QtGui -I/usr/lib/qt/include -I. -o mainwindow.o src/mainwindow.cpp
src/mainwindow.cpp: In member function ‘void MainWindow::setPath()’:
src/mainwindow.cpp:37:18: error: base operand of ‘->’ has non-pointer type ‘QString’
src/mainwindow.cpp:37:32: error: base operand of ‘->’ has non-pointer type ‘QString’
src/mainwindow.cpp:37:48: error: base operand of ‘->’ has non-pointer type ‘QString’
src/mainwindow.cpp:38:13: error: return-statement with a value, in function returning 'void' [-fpermissive]
src/mainwindow.cpp:47:14: error: base operand of ‘->’ has non-pointer type ‘QString’
src/mainwindow.cpp:47:28: error: base operand of ‘->’ has non-pointer type ‘QString’
src/mainwindow.cpp:47:44: error: base operand of ‘->’ has non-pointer type ‘QString’
make: *** [mainwindow.o] Error 1


mainwindow.h

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef __MAINWINDOW_H__
#define __MAINWINDOW_H__

#include <QtGui>
#include "mainwidget.h"
#include "outputwidget.h"

class MainWindow:public QMainWindow
{
Q_OBJECT
public:
	MainWindow();
signals:
	void path(const QString& konsole, const QString& shell, const QString& backend);
private:
	MainWidget* mainWidget;
	OutputWidget* outputWidget;
	
	QToolBar* toolBar;
	QAction* generateAct;
	QAction* saveAct;
	QAction* helpAct;
	QAction* aboutAct;
	QAction* buildAct;
	
	QString konsole;
	QString shell;
	QString backend;
	
	void init_actions();
	void init_toolBars();
	void init_statusBar();
	void init_filepath();
	void set_filepath();
	void setPath();
	
	static bool isConfigDirExisting();
	static QString getConfigDirPath();
public slots:
	void generate();
	void save();
	void help();
	void about();
	void build();
};

#endif // __MAINWINDOW_H__


mainwindow.cpp (I have stripped off the working parts)

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "mainwindow.h"
#include <QProcess>
#include <QSettings>
#include <QDir>

MainWindow::MainWindow()
{
	setWindowTitle(tr("QSlaxBuild - brought to you by FluxFlux"));
	mainWidget=new MainWidget(tr("SlaxBuild"),this);
	mainWidget->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetClosable);
	outputWidget=new OutputWidget(tr("Output"),this);
	outputWidget->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetClosable);
	setCentralWidget(mainWidget);
	addDockWidget(Qt::BottomDockWidgetArea,outputWidget);

	QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, "$HOME/.qslaxbuild");

	setPath();
	init_actions();
	init_toolBars();
	init_statusBar();
	init_filepath();
}

void MainWindow::setPath()
{
	if(!isConfigDirExisting())
	{
	   QString konsole = "/usr/bin/konsole";
	   QString shell = "/bin/bash";
	   QString backend = "/sbin/slax";

		this->konsole=konsole;
		this->shell=shell;
		this->backend=backend;

		path(konsole->text(),shell->text(),backend->text());
		return TRUE;
	}
	QString fileName = getConfigDirPath() + "qslaxbuildrc";
	QSettings settings(fileName, QSettings::IniFormat);

	this->konsole=(settings.value("konsole").toString());
	this->shell=(settings.value("shell").toString());
	this->backend=(settings.value("backend").toString());

	path(konsole->text(),shell->text(),backend->text());
	
}

bool MainWindow::isConfigDirExisting()
{
	return QDir::home().exists(".qslaxbuild");
}

QString MainWindow::getConfigDirPath()
{
	return QDir::homePath() + QDir::separator() + ".qslaxbuild" + QDir::separator();
}

............................................
# Working parts stripped off
............................................

void MainWindow::build()
{
	QFile file;
	QString strfile;
	
	file.setFileName(konsole);
	if(!file.exists())
	{
		QMessageBox::critical (this, tr("Error!"),tr("Can't open file :")+konsole+"\n"+
			tr("Please configure in $HOME/.qslaxbuild/qslaxbuildrc!"),
			QMessageBox::Ok);
	}
	
	file.setFileName(shell);
	if(!file.exists())
	{
		int rtv;
		rtv=QMessageBox::critical (this, tr("Error!"),tr("Can't open file :")+shell+"\n"+
			tr("Please configure in $HOME/.qslaxbuild/qslaxbuildrc!"),
			QMessageBox::Ok);
	}
	
	file.setFileName(backend);
	if(!file.exists())
	{
		int rtv;
		rtv=QMessageBox::critical (this, tr("Error!"),tr("Can't open file :")+backend+"\n"+
			tr("Please configure in $HOME/.qslaxbuild/qslaxbuildrc!"),
			QMessageBox::Ok);
	}
	
	strfile=QFileDialog::getOpenFileName(this, tr("Open File"),
					QDir::homePath()+tr("/untitled.SlaxBuild"),
					tr("SlaxBuild (*.SlaxBuild)"));
	if(!strfile.isEmpty())
	{
		file.setFileName(strfile);
		if(!file.exists())
		{
			QMessageBox::critical ( this, tr("Error!"), tr("Can't open file :")+strfile,
				QMessageBox::Ok);
			return;
		}
	}
	QStringList args;
	args<<"--noclose"<<"-e"<<shell<<"-ba"<<strfile;
	
	QProcess::execute(konsole,args);
}


It would be nice if someone could show me which screws to turn to get this working.

Thanks and regards,

Manfred

This post has been edited 4 times, last edit by "FluxFlux" (Aug 9th 2013, 8:21am) with the following reason: marked as solved


2

Thursday, August 8th 2013, 3:07pm

Your QString objects are statically created so you cannot dereference them as if they were pointers (->). Moreover I don't think that QString class actually has a method text()...(?)

3

Friday, August 9th 2013, 8:24am

Thanks for your answer,

as I wrote in the post, there must be noobish mistakes...

Nevertheless I have soved my problem by replacing the QSettings calls with
a widget in which the users can change and commit the tool paths at runtime.

Regards,

Manfred

Used tags

QSettings, Qt4