QObject::connect question
-
I was reading a beginners tutor on a push button that closes then a user clicks it. in qt creator I created a new qt gui application using the default file names. I then went to the form designer and put on the main window a push button.
in the mainwindow.cpp, I created the following code to put into the push button click function. The problem is that in the code &a, the "a" is defined in the main.cpp file only. I would like to close the application from the mainwindow.cpp instead but i don't know how or even if that is possible. I would like to close it in the mainwindow.cpp because that way i could do my from design in the designer, select my signal and then do the code all within the mainwindow.cpp. is that possible to do?
@void MainWindow::on_pushButton_clicked()
{
QObject::connect(&ui;->pushButton, SIGNAL(clicked()), &a, SLOT(quit()));
quit.show();
}@here is the mainwindow.cpp code.
@#include "mainwindow.h"
#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::on_pushButton_clicked()
{
QObject::connect(&quit;, SIGNAL(clicked()), &a, SLOT(quit()));
quit.show();}@
-
All right, you can also take a look at this one "New Signal&Slot; syntax":http://developer.qt.nokia.com/wiki/New_Signal_Slot_Syntax