Results 1 to 3 of 3

Thread: Undeclared Identifier from ui_ header

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2011
    Location
    The Internet
    Posts
    29
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Undeclared Identifier from ui_ header

    I am currently trying to fill a QTreeView and having some issues with my mainwindow.cpp file seeing the definition of the tree in ui_mainwindow.h. Here are the pieces of code I feel should let this variable be defined:

    from ui_mainwindow.h (generated)

    Qt Code:
    1. treeView_test = new QTreeView(groupBox);
    2. treeView_test->setObjectName(QString::fromUtf8("treeView_test"));
    3. treeView_test->setGeometry(QRect(80, 320, 211, 471));
    To copy to clipboard, switch view to plain text mode 
    from mainwindow.cpp

    Qt Code:
    1. treeView_test->setModel(standardModel);
    2. treeView_test->expandAll();
    To copy to clipboard, switch view to plain text mode 
    from mainwindow.h

    Qt Code:
    1. #include "ui_mainwindow.h"
    2.  
    3. class QTreeView;
    To copy to clipboard, switch view to plain text mode 

    I am receiving the following error in mainwindow.cpp (the first location treeView_test is set)
    Qt Code:
    1. error 2065: 'treeView_test' : undeclared identifier
    To copy to clipboard, switch view to plain text mode 

    Why can't mainwindow.cpp see treeView_test from ui_mainwindow.h? any ideas? Thanks!

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Undeclared Identifier from ui_ header

    You need to create an instance of Ui::MainWindowUi class (or whatever is the name in ui_mainWindow.h file), then call setupUi( ) to actually create the ui elements. This is usually done in your custom class' constructor:
    Qt Code:
    1. // .h
    2. #include "ui_mainWindow.h"
    3.  
    4. class MainWindow: public QMainWindow
    5. {
    6. //...
    7. protected:
    8. Ui::MainWindowUi ui;
    9. };
    10. // .cpp
    11. MainWindow::MainWindow( QWidget * parent ) : QMainWindow(parent){
    12. ui.setupUi(this);
    13. }
    To copy to clipboard, switch view to plain text mode 
    Then you can use the treeView:
    Qt Code:
    1. void MainWindow::doSomething(){
    2. ui.treeView_test->...
    3. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Aug 2011
    Location
    The Internet
    Posts
    29
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Undeclared Identifier from ui_ header

    thanks! i was forgetting the ui. in front of all the treeView declarations!

Similar Threads

  1. syntax error : identifier 'QSqlRelationalDelegate'
    By sticcino in forum Qt Programming
    Replies: 6
    Last Post: 16th September 2011, 10:15
  2. Dynamic objects without identifier...
    By Bill in forum Newbie
    Replies: 7
    Last Post: 18th August 2009, 15:17
  3. undeclared QSslCertificate
    By labaga in forum Newbie
    Replies: 5
    Last Post: 3rd December 2008, 09:30
  4. Q_UINT32 undeclared !
    By darshan.hardas in forum Qt Programming
    Replies: 1
    Last Post: 23rd October 2007, 09:11
  5. undeclared method - GUI Styles
    By Amanda in forum Qt Programming
    Replies: 2
    Last Post: 19th November 2006, 13:43

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
  •  
Qt is a trademark of The Qt Company.