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;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private slots:
void on_actionCopy_triggered();
protected:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
#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
To copy to clipboard, switch view to plain text mode
Here is the mainwindow.cpp file.
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *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();
}
#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();
}
To copy to clipboard, switch view to plain text mode
Here is the wordpad.h file.
#ifndef WORDPAD_H
#define WORDPAD_H
class WordPad
{
public:
WordPad();
void copy();
};
#endif // WORDPAD_H
#ifndef WORDPAD_H
#define WORDPAD_H
class WordPad
{
public:
WordPad();
void copy();
};
#endif // WORDPAD_H
To copy to clipboard, switch view to plain text mode
Here is the wordpad.cpp file.
#include "wordpad.h"
WordPad::WordPad()
{
}
void WordPad::copy()
{
ui->textEdit->copy();
}
#include "wordpad.h"
WordPad::WordPad()
{
}
void WordPad::copy()
{
ui->textEdit->copy();
}
To copy to clipboard, switch view to plain text mode
Bookmarks