PDA

View Full Version : How To Solve This 'ui' was not declared in this scope



Kistlak
7th December 2017, 11:15
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.


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "wordpad.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow, WordPad
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

private slots:
void on_actionCopy_triggered();

protected:
Ui::MainWindow *ui;

};

#endif // MAINWINDOW_H



Here is the mainwindow.cpp file.


#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

this->setCentralWidget(ui->textEdit);
}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::on_actionCopy_triggered()
{
WordPad copymain;

copymain.copy();
}



Here is the wordpad.h file.


#ifndef WORDPAD_H
#define WORDPAD_H


class WordPad
{
public:
WordPad();
void copy();

};

#endif // WORDPAD_H



Here is the wordpad.cpp file.


#include "wordpad.h"

WordPad::WordPad()
{

}

void WordPad::copy()
{
ui->textEdit->copy();
}

high_flyer
7th December 2017, 16:01
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.