PDA

View Full Version : QSettings error



darlene
5th May 2011, 06:52
Hi! This is my first time to program in Qt and having problems with QSettings. I followed a code i saw online



private:
QSettings settings;


and adding this to the constructor:


MainWindow::MainWindow(QWidget *parent) :
...
settings("Contemposoft", "SimpleTextEdit")


but i get the folowing error:

no match for call to '(QSettings) (const char [5], const char [8])'

thanks

ChrisW67
5th May 2011, 07:15
That error message does not match the code lines you posted (it implies you used strings of 5 and 8 characters).

The error arises because you have put the attempt to initialize "settings" inside the constructor (where it is already default constructed) rather than in the constructor initialization list (where you have the opportunity to dictate how to construct it).



class MainWindow: public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *p = 0): QMainWindow(p),
settings("Contemposoft", "SimpleTextEdit")
{
// up there ^^^^ , not in here
}
...
private:
QSettings settings;
};