Reputation: 702
I am writing a simple editor i Qt and C++. I want to have tabs, so after creating a new document, I want to open this in a new tab. My code:
// mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
setWindowTitle("emacs");
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionExit_triggered()
{
qApp->exit(0);
}
void MainWindow::on_actionNew_triggered()
{
// what to write here?
}
// main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
// mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_actionExit_triggered();
void on_actionNew_triggered();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
I have successfully managed to create an action to exit the program. But when I try something like this: tabWidget->addTab(new QWidget(),"new tab");
is complaints that tabWidget was not declared in the scope. Anybody? Thanks!
Upvotes: 0
Views: 506
Reputation: 206859
tabWidget
is not a member of your MainWindow
class, I'm guessing its an object you defined in your ui
file, so try:
ui->tabWidget->addTab(...);
Upvotes: 1