Hello all!
I'm a completly newby in QT. I've a little problem:
I've made a two files:
main.cpp
|
Source code
|
1
2
3
4
5
6
7
8
9
10
|
#include <QtGui/QApplication>
#include "widget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
|
widget.cpp
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#include "widget.h"
#include "ui_widget.h"
#include <QtGui>
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::WidgetClass) {
ui->setupUi(this);
connect( btn1, SIGNAL( clicked() ), this, SLOT( getPath() ) );
}
void Widget::getPath() {
QString path; path = QFileDialog::getOpenFileName( this, "Choose a file to open", QString::null, QString::null);
}
Widget::~Widget() {
delete ui;
}
|
and finaly
widget.h
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
#ifndef WIDGET_H
#define WIDGET_H
#include <QtGui/QWidget>
namespace Ui { class WidgetClass; }
class Widget : public QWidget {
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
public slots:
void getPath();
private:
Ui::WidgetClass *ui;
};
#endif // WIDGET_H
|
There is a one button (name btn1) on the form (widget.ui).
When I'm trying compile my application a get an error:
C:/qt_workspace/xxxxx/widget.cpp:9: error: `btn1' was not declared in this scope
What I should do, for btn1 can be "visible" in file widget.cpp?
Thank you very much for your time.