Results 1 to 6 of 6

Thread: ui not declared in scope

  1. #1
    Join Date
    Mar 2011
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question ui not declared in scope

    HEADER FILE
    Qt Code:
    1. #include <QMainWindow>
    2. #include "ui_form.h"
    3.  
    4. class Form1:public QMainWindow
    5. {
    6. Q_OBJECT
    7. public:
    8. Form1();
    9. ~Form1();
    10.  
    11. protected slots:
    12. void function1();
    13. }
    To copy to clipboard, switch view to plain text mode 

    CPP FILE
    Qt Code:
    1. #include "form1.h"
    2. #include <QDebug>
    3. #include <QFile>
    4. #include <QTextStream>
    5. #include <QTimer>
    6. #include <QDialog>
    7. #include <QMessageBox>
    8. #include <QStringListModel>
    9.  
    10. Form1::Form1():QMainWindow(NULL,0)
    11. {
    12. connect(ui.action_button, SIGNAL(clicked()), this, SLOT(function1()));
    13. }
    14.  
    15. void Form1::function1()
    16. {
    17. }
    18.  
    19. Form1::~Form1()
    20. {
    21. }
    To copy to clipboard, switch view to plain text mode 

    Error is on line 12 in the CPP file.
    Last edited by steve.bush; 18th March 2011 at 23:02.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ui not declared in scope

    So on what line of what file are you getting that error? We can't read minds.

  3. #3
    Join Date
    Mar 2011
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: ui not declared in scope

    Quote Originally Posted by squidge View Post
    So on what line of what file are you getting that error? We can't read minds.
    Line 12 .

  4. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: ui not declared in scope

    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 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>)

  5. #5
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: ui not declared in scope

    Form1::Form1():QMainWindow(NULL,0)

    It should be like this.....
    ui(new Ui::QtMySql)

  6. #6
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: ui not declared in scope

    @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:
    Qt Code:
    1. Form1::Form1(QWidget* parent = 0) : QMainWindow(parent, 0)
    To copy to clipboard, switch view to plain text mode 

    @Steve: the main problem is that he forgot to integrate the generated code, he only included the header ui_form.h:
    Qt Code:
    1. #include "ui_form.h"
    2.  
    3. class Form1:public QMainWindow
    4. {
    5. Q_OBJECT
    6. public:
    7. Form1();
    8. ~Form1();
    9.  
    10. protected slots:
    11. void function1();
    12. //this needs to be added:
    13. private:
    14. Ui_Form ui; //object or pointer whatever you prefer
    15. // or you can use the class from Ui nanespace:
    16. // Ui::Form ui;
    17. // read the documentation page linked in my previous post
    18. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. GetFileSizeEx was not declared in this scope
    By Threepwood in forum Qt Programming
    Replies: 2
    Last Post: 8th February 2011, 12:03
  2. `lineEdit' was not declared in this scope?
    By i4ba1 in forum Qt Programming
    Replies: 2
    Last Post: 18th November 2009, 14:36
  3. QDomDocument was not declared in this scope
    By grantbj74 in forum Newbie
    Replies: 5
    Last Post: 25th August 2009, 09:43
  4. 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
  5. Replies: 2
    Last Post: 28th December 2007, 18:30

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.