Aamir
16th July 2010, 06:33
Hello,
I am a newbie in QT. I tried making a browse button to display file dialog but on complie time it gives an error:
"pushButton was not declared in this scope"
I have included the appropriate headers.
Here is the header:
#ifndef PT_H
#define PT_H
#include <QWidget>
#include<QPushButton>
#include "pt.h"
namespace Ui {
class pt;
}
class pt : public QWidget {
Q_OBJECT
public:
pt(QWidget *parent = 0);
~pt();
public slots:
void browse();
protected:
void changeEvent(QEvent *e);
private:
Ui::pt *ui;
};
#endif // PT_H
Here is main.cpp
#include <QtGui/QApplication>
#include<QtGui/QPushButton>
#include<QFileDialog>
#include "pt.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
pt w;
w.show();
return a.exec();
}
and finally the pt.cpp (pt my project name :))
#include<QtGui/QApplication>
#include<QFileDialog>
#include<QtGui>
#include<QtGui/QPushButton>
#include "pt.h"
#include "ui_pt.h"
pt::pt(QWidget *parent) :
QWidget(parent),
ui(new Ui::pt)
{
ui->setupUi(this);
connect( pushButton, SIGNAL( clicked() ), this, SLOT( browse() ) );
}
pt::~pt()
{
delete ui;
}
void pt::browse()
{
QString path;
path = QFileDialog::getOpenFileName(
this,
"Choose a file to open",
QString::null,
QString::null);
ui->lineEdit->setText( path );
}
void pt::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
Somebody please help me on this !!
Thanks.
I am a newbie in QT. I tried making a browse button to display file dialog but on complie time it gives an error:
"pushButton was not declared in this scope"
I have included the appropriate headers.
Here is the header:
#ifndef PT_H
#define PT_H
#include <QWidget>
#include<QPushButton>
#include "pt.h"
namespace Ui {
class pt;
}
class pt : public QWidget {
Q_OBJECT
public:
pt(QWidget *parent = 0);
~pt();
public slots:
void browse();
protected:
void changeEvent(QEvent *e);
private:
Ui::pt *ui;
};
#endif // PT_H
Here is main.cpp
#include <QtGui/QApplication>
#include<QtGui/QPushButton>
#include<QFileDialog>
#include "pt.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
pt w;
w.show();
return a.exec();
}
and finally the pt.cpp (pt my project name :))
#include<QtGui/QApplication>
#include<QFileDialog>
#include<QtGui>
#include<QtGui/QPushButton>
#include "pt.h"
#include "ui_pt.h"
pt::pt(QWidget *parent) :
QWidget(parent),
ui(new Ui::pt)
{
ui->setupUi(this);
connect( pushButton, SIGNAL( clicked() ), this, SLOT( browse() ) );
}
pt::~pt()
{
delete ui;
}
void pt::browse()
{
QString path;
path = QFileDialog::getOpenFileName(
this,
"Choose a file to open",
QString::null,
QString::null);
ui->lineEdit->setText( path );
}
void pt::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
Somebody please help me on this !!
Thanks.