(ERROR HELP) pushButton was not declared in this scope.
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:
Code:
#ifndef PT_H
#define PT_H
#include <QWidget>
#include<QPushButton>
#include "pt.h"
namespace Ui {
class pt;
}
Q_OBJECT
public:
~pt();
public slots:
void browse();
protected:
private:
Ui::pt *ui;
};
#endif // PT_H
Here is main.cpp
Code:
#include <QtGui/QApplication>
#include<QtGui/QPushButton>
#include<QFileDialog>
#include "pt.h"
int main(int argc, char *argv[])
{
pt w;
w.show();
return a.exec();
}
and finally the pt.cpp (pt my project name :))
Code:
#include<QtGui/QApplication>
#include<QFileDialog>
#include<QtGui>
#include<QtGui/QPushButton>
#include "pt.h"
#include "ui_pt.h"
ui(new Ui::pt)
{
ui->setupUi(this);
connect( pushButton, SIGNAL( clicked() ), this, SLOT( browse() ) );
}
pt::~pt()
{
delete ui;
}
void pt::browse()
{
this,
"Choose a file to open",
ui->lineEdit->setText( path );
}
void pt
::changeEvent(QEvent *e
) {
switch (e->type()) {
ui->retranslateUi(this);
break;
default:
break;
}
}
Somebody please help me on this !!
Thanks.
Re: (ERROR HELP) pushButton was not declared in this scope.
pt.h
Code:
#ifndef PT_H
#define PT_H
#include <QWidget>
//#include<QPushButton>
//#include "pt.h"
namespace Ui {
class pt;
}
Q_OBJECT
public:
~pt();
public slots:
void browse();
protected:
private:
Ui::pt *ui;
};
#endif // PT_H
[/CODE]
main.cpp
Code:
#include <QtGui/QApplication>
//#include<QtGui/QPushButton>
//#include<QFileDialog>
#include "pt.h"
int main(int argc, char *argv[])
{
pt w;
w.show();
return a.exec();
}
pt.cpp
Code:
//#include<QtGui/QApplication>
#include<QFileDialog>
//#include<QtGui>
//#include<QtGui/QPushButton>
#include "pt.h"
#include "ui_pt.h"
ui(new Ui::pt)
{
ui->setupUi(this);
// connect( pushButton, SIGNAL( clicked() ), this, SLOT( browse() ) );
connect( ui->pushButton, SIGNAL( clicked() ), this, SLOT( browse() ) );
}
pt::~pt()
{
delete ui;
}
void pt::browse()
{
this,
"Choose a file to open",
ui->lineEdit->setText( path );
}
void pt
::changeEvent(QEvent *e
) {
switch (e->type()) {
ui->retranslateUi(this);
break;
default:
break;
}
}
Does this work?
Re: (ERROR HELP) pushButton was not declared in this scope.
Quote:
Originally Posted by
saa7_go
pt.h
Code:
#ifndef PT_H
#define PT_H
#include <QWidget>
//#include<QPushButton>
//#include "pt.h"
namespace Ui {
class pt;
}
Q_OBJECT
public:
~pt();
public slots:
void browse();
protected:
private:
Ui::pt *ui;
};
#endif // PT_H
[/CODE]
main.cpp
Code:
#include <QtGui/QApplication>
//#include<QtGui/QPushButton>
//#include<QFileDialog>
#include "pt.h"
int main(int argc, char *argv[])
{
pt w;
w.show();
return a.exec();
}
pt.cpp
Code:
//#include<QtGui/QApplication>
#include<QFileDialog>
//#include<QtGui>
//#include<QtGui/QPushButton>
#include "pt.h"
#include "ui_pt.h"
ui(new Ui::pt)
{
ui->setupUi(this);
// connect( pushButton, SIGNAL( clicked() ), this, SLOT( browse() ) );
connect( ui->pushButton, SIGNAL( clicked() ), this, SLOT( browse() ) );
}
pt::~pt()
{
delete ui;
}
void pt::browse()
{
this,
"Choose a file to open",
ui->lineEdit->setText( path );
}
void pt
::changeEvent(QEvent *e
) {
switch (e->type()) {
ui->retranslateUi(this);
break;
default:
break;
}
}
Does this work?
yes man its works.. Thanks thanks thanks a lot :):)