There is no problem with this code, if you emit the signal after making the connection, everything works as expected.
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
void callSignal();
~MainWindow();
private slots:
void test();
signals:
void _connected(int);
private:
Ui::MainWindow *ui;
};
#endif
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
void callSignal();
~MainWindow();
private slots:
void test();
signals:
void _connected(int);
private:
Ui::MainWindow *ui;
};
#endif
To copy to clipboard, switch view to plain text mode
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtGui>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
bool c = connect(this,SIGNAL(_connected(int)), this, SLOT(test()));
callSignal();
}
void MainWindow::callSignal()
{
emit _connected(1);
}
void MainWindow::test(){
}
MainWindow::~MainWindow()
{
delete ui;
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtGui>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
bool c = connect(this,SIGNAL(_connected(int)), this, SLOT(test()));
callSignal();
QMessageBox::information(0, "Connect()", QString::number(c)); // shows c = 1 "true"
}
void MainWindow::callSignal()
{
emit _connected(1);
}
void MainWindow::test(){
QMessageBox::information(0, "slot", "test");
}
MainWindow::~MainWindow()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
Bookmarks