PDA

View Full Version : ui not declared in scope



steve.bush
18th March 2011, 22:44
HEADER FILE


#include <QMainWindow>
#include "ui_form.h"

class Form1:public QMainWindow
{
Q_OBJECT
public:
Form1();
~Form1();

protected slots:
void function1();
}


CPP FILE


#include "form1.h"
#include <QDebug>
#include <QFile>
#include <QTextStream>
#include <QTimer>
#include <QDialog>
#include <QMessageBox>
#include <QStringListModel>

Form1::Form1():QMainWindow(NULL,0)
{
connect(ui.action_button, SIGNAL(clicked()), this, SLOT(function1()));
}

void Form1::function1()
{
}

Form1::~Form1()
{
}



Error is on line 12 in the CPP file.

squidge
18th March 2011, 22:52
So on what line of what file are you getting that error? We can't read minds.

steve.bush
18th March 2011, 23:03
So on what line of what file are you getting that error? We can't read minds.

Line 12 .

Zlatomir
18th March 2011, 23:03
That is most likely because you don't have a ui member object or pointer or not inheriting from the ui auto-generated class.

See here (http://doc.qt.nokia.com/4.7/designer-using-a-ui-file.html) the methods for using ui in the cpp file (i recommend the private member or pointer <don't forget to new the ui* if you use a pointer>)

Gokulnathvc
19th March 2011, 05:33
Form1::Form1():QMainWindow(NULL,0)

It should be like this.....


ui(new Ui::QtMySql)

Zlatomir
19th March 2011, 08:58
@Gokulnathvc: the only problem with the line you pointed to is that is doesn't take a parent and pass is to the QMainWindow constructor:

Form1::Form1(QWidget* parent = 0) : QMainWindow(parent, 0)

@Steve: the main problem is that he forgot to integrate the generated code, he only included the header ui_form.h:


#include "ui_form.h"

class Form1:public QMainWindow
{
Q_OBJECT
public:
Form1();
~Form1();

protected slots:
void function1();
//this needs to be added:
private:
Ui_Form ui; //object or pointer whatever you prefer
// or you can use the class from Ui nanespace:
// Ui::Form ui;
// read the documentation page linked in my previous post
}