Results 1 to 2 of 2

Thread: How To Solve This 'ui' was not declared in this scope

  1. #1
    Join Date
    Dec 2017
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Question How To Solve This 'ui' was not declared in this scope

    I am creating WordPad using C++ by using QT framework. And I have created mainwindow.cpp and mainwindow.h files. Then I have created wordpad.cpp and wordpad.h files. Still, I am very new to QT and C++. So, I don't know lots of things.

    But , when I try to build the project , it gives me this error in wordpad.cpp file.

    D:\Projects & Tests\C++\Projects\WordPad\wordpad.cpp:10: error: 'ui' was not declared in this scope
    ui->textEdit->copy();
    ^
    I added textEdit from QT GUI.

    How can I Fix this ??

    Here is the mainwindow.h file.
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include "wordpad.h"
    6.  
    7. namespace Ui {
    8. class MainWindow;
    9. }
    10.  
    11. class MainWindow : public QMainWindow, WordPad
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. explicit MainWindow(QWidget *parent = 0);
    17. ~MainWindow();
    18.  
    19. private slots:
    20. void on_actionCopy_triggered();
    21.  
    22. protected:
    23. Ui::MainWindow *ui;
    24.  
    25. };
    26.  
    27. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    Here is the mainwindow.cpp file.
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9.  
    10. this->setCentralWidget(ui->textEdit);
    11. }
    12.  
    13. MainWindow::~MainWindow()
    14. {
    15. delete ui;
    16. }
    17.  
    18. void MainWindow::on_actionCopy_triggered()
    19. {
    20. WordPad copymain;
    21.  
    22. copymain.copy();
    23. }
    To copy to clipboard, switch view to plain text mode 

    Here is the wordpad.h file.
    Qt Code:
    1. #ifndef WORDPAD_H
    2. #define WORDPAD_H
    3.  
    4.  
    5. class WordPad
    6. {
    7. public:
    8. WordPad();
    9. void copy();
    10.  
    11. };
    12.  
    13. #endif // WORDPAD_H
    To copy to clipboard, switch view to plain text mode 

    Here is the wordpad.cpp file.
    Qt Code:
    1. #include "wordpad.h"
    2.  
    3. WordPad::WordPad()
    4. {
    5.  
    6. }
    7.  
    8. void WordPad::copy()
    9. {
    10. ui->textEdit->copy();
    11. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by high_flyer; 7th December 2017 at 16:56.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How To Solve This 'ui' was not declared in this scope

    1. Don't double post
    2. For code use CODE tags not QTCLASS tags.

    To your question:
    How can I Fix this ??
    Where in your WordPad class is any information about a 'ui' member?
    That it the error you got.
    In your MainWindows you have it defined, but not in your WorPad class.
    Last edited by high_flyer; 7th December 2017 at 17:05.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 2
    Last Post: 12th April 2016, 00:38
  2. Not declared in scope
    By mikea in forum Newbie
    Replies: 3
    Last Post: 4th October 2014, 09:06
  3. 'fileMenu' was not declared in the scope
    By lapdx in forum Newbie
    Replies: 5
    Last Post: 6th December 2012, 23:16
  4. endl' was not declared in this scope
    By k.qasempour in forum Newbie
    Replies: 8
    Last Post: 21st June 2012, 10:36
  5. ui not declared in scope
    By steve.bush in forum Newbie
    Replies: 5
    Last Post: 19th March 2011, 09:58

Tags for this Thread

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.