Results 1 to 3 of 3

Thread: (ERROR HELP) pushButton was not declared in this scope.

  1. #1
    Join Date
    Jul 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy (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:
    Qt Code:
    1. #ifndef PT_H
    2. #define PT_H
    3.  
    4. #include <QWidget>
    5. #include<QPushButton>
    6. #include "pt.h"
    7.  
    8. namespace Ui {
    9. class pt;
    10. }
    11.  
    12. class pt : public QWidget {
    13. Q_OBJECT
    14. public:
    15. pt(QWidget *parent = 0);
    16. ~pt();
    17.  
    18. public slots:
    19. void browse();
    20.  
    21. protected:
    22. void changeEvent(QEvent *e);
    23.  
    24. private:
    25. Ui::pt *ui;
    26. };
    27.  
    28. #endif // PT_H
    To copy to clipboard, switch view to plain text mode 

    Here is main.cpp
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include<QtGui/QPushButton>
    3. #include<QFileDialog>
    4. #include "pt.h"
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication a(argc, argv);
    9. pt w;
    10. w.show();
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    and finally the pt.cpp (pt my project name )
    Qt Code:
    1. #include<QtGui/QApplication>
    2. #include<QFileDialog>
    3. #include<QtGui>
    4. #include<QtGui/QPushButton>
    5. #include "pt.h"
    6. #include "ui_pt.h"
    7.  
    8. pt::pt(QWidget *parent) :
    9. QWidget(parent),
    10. ui(new Ui::pt)
    11. {
    12. ui->setupUi(this);
    13.  
    14. connect( pushButton, SIGNAL( clicked() ), this, SLOT( browse() ) );
    15. }
    16.  
    17. pt::~pt()
    18. {
    19. delete ui;
    20. }
    21.  
    22. void pt::browse()
    23. {
    24. QString path;
    25.  
    26. path = QFileDialog::getOpenFileName(
    27. this,
    28. "Choose a file to open",
    29. QString::null,
    30. QString::null);
    31.  
    32. ui->lineEdit->setText( path );
    33. }
    34.  
    35. void pt::changeEvent(QEvent *e)
    36. {
    37. QWidget::changeEvent(e);
    38. switch (e->type()) {
    39. case QEvent::LanguageChange:
    40. ui->retranslateUi(this);
    41. break;
    42. default:
    43. break;
    44. }
    45. }
    To copy to clipboard, switch view to plain text mode 

    Somebody please help me on this !!
    Thanks.

  2. #2
    Join Date
    Jun 2010
    Location
    Salatiga, Indonesia
    Posts
    160
    Thanks
    11
    Thanked 32 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: (ERROR HELP) pushButton was not declared in this scope.

    pt.h
    Qt Code:
    1. #ifndef PT_H
    2. #define PT_H
    3.  
    4. #include <QWidget>
    5. //#include<QPushButton>
    6. //#include "pt.h"
    7.  
    8. namespace Ui {
    9. class pt;
    10. }
    11.  
    12. class pt : public QWidget {
    13. Q_OBJECT
    14. public:
    15. pt(QWidget *parent = 0);
    16. ~pt();
    17.  
    18. public slots:
    19. void browse();
    20.  
    21. protected:
    22. void changeEvent(QEvent *e);
    23.  
    24. private:
    25. Ui::pt *ui;
    26. };
    27.  
    28. #endif // PT_H
    To copy to clipboard, switch view to plain text mode 
    [/CODE]

    main.cpp
    Qt Code:
    1. #include <QtGui/QApplication>
    2. //#include<QtGui/QPushButton>
    3. //#include<QFileDialog>
    4. #include "pt.h"
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication a(argc, argv);
    9. pt w;
    10. w.show();
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    pt.cpp
    Qt Code:
    1. //#include<QtGui/QApplication>
    2. #include<QFileDialog>
    3. //#include<QtGui>
    4. //#include<QtGui/QPushButton>
    5. #include "pt.h"
    6. #include "ui_pt.h"
    7.  
    8. pt::pt(QWidget *parent) :
    9. QWidget(parent),
    10. ui(new Ui::pt)
    11. {
    12. ui->setupUi(this);
    13.  
    14. // connect( pushButton, SIGNAL( clicked() ), this, SLOT( browse() ) );
    15. connect( ui->pushButton, SIGNAL( clicked() ), this, SLOT( browse() ) );
    16. }
    17.  
    18. pt::~pt()
    19. {
    20. delete ui;
    21. }
    22.  
    23. void pt::browse()
    24. {
    25. QString path;
    26.  
    27. path = QFileDialog::getOpenFileName(
    28. this,
    29. "Choose a file to open",
    30. QString::null,
    31. QString::null);
    32.  
    33. ui->lineEdit->setText( path );
    34. }
    35.  
    36. void pt::changeEvent(QEvent *e)
    37. {
    38. QWidget::changeEvent(e);
    39. switch (e->type()) {
    40. case QEvent::LanguageChange:
    41. ui->retranslateUi(this);
    42. break;
    43. default:
    44. break;
    45. }
    46. }
    To copy to clipboard, switch view to plain text mode 

    Does this work?

  3. #3
    Join Date
    Jul 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: (ERROR HELP) pushButton was not declared in this scope.

    Quote Originally Posted by saa7_go View Post
    pt.h
    Qt Code:
    1. #ifndef PT_H
    2. #define PT_H
    3.  
    4. #include <QWidget>
    5. //#include<QPushButton>
    6. //#include "pt.h"
    7.  
    8. namespace Ui {
    9. class pt;
    10. }
    11.  
    12. class pt : public QWidget {
    13. Q_OBJECT
    14. public:
    15. pt(QWidget *parent = 0);
    16. ~pt();
    17.  
    18. public slots:
    19. void browse();
    20.  
    21. protected:
    22. void changeEvent(QEvent *e);
    23.  
    24. private:
    25. Ui::pt *ui;
    26. };
    27.  
    28. #endif // PT_H
    To copy to clipboard, switch view to plain text mode 
    [/CODE]

    main.cpp
    Qt Code:
    1. #include <QtGui/QApplication>
    2. //#include<QtGui/QPushButton>
    3. //#include<QFileDialog>
    4. #include "pt.h"
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication a(argc, argv);
    9. pt w;
    10. w.show();
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    pt.cpp
    Qt Code:
    1. //#include<QtGui/QApplication>
    2. #include<QFileDialog>
    3. //#include<QtGui>
    4. //#include<QtGui/QPushButton>
    5. #include "pt.h"
    6. #include "ui_pt.h"
    7.  
    8. pt::pt(QWidget *parent) :
    9. QWidget(parent),
    10. ui(new Ui::pt)
    11. {
    12. ui->setupUi(this);
    13.  
    14. // connect( pushButton, SIGNAL( clicked() ), this, SLOT( browse() ) );
    15. connect( ui->pushButton, SIGNAL( clicked() ), this, SLOT( browse() ) );
    16. }
    17.  
    18. pt::~pt()
    19. {
    20. delete ui;
    21. }
    22.  
    23. void pt::browse()
    24. {
    25. QString path;
    26.  
    27. path = QFileDialog::getOpenFileName(
    28. this,
    29. "Choose a file to open",
    30. QString::null,
    31. QString::null);
    32.  
    33. ui->lineEdit->setText( path );
    34. }
    35.  
    36. void pt::changeEvent(QEvent *e)
    37. {
    38. QWidget::changeEvent(e);
    39. switch (e->type()) {
    40. case QEvent::LanguageChange:
    41. ui->retranslateUi(this);
    42. break;
    43. default:
    44. break;
    45. }
    46. }
    To copy to clipboard, switch view to plain text mode 

    Does this work?
    yes man its works.. Thanks thanks thanks a lot

Similar Threads

  1. `lineEdit' was not declared in this scope?
    By i4ba1 in forum Qt Programming
    Replies: 2
    Last Post: 18th November 2009, 14:36
  2. QDomDocument was not declared in this scope
    By grantbj74 in forum Newbie
    Replies: 5
    Last Post: 25th August 2009, 09:43
  3. glutSolidSphere was not declared in this scope error
    By nuts_fever_007 in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2009, 04:56
  4. Replies: 2
    Last Post: 28th December 2007, 18:30
  5. error: 'connect' was not declared in this scope ??
    By Morea in forum Qt Programming
    Replies: 2
    Last Post: 14th January 2007, 15:27

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.