Reputation: 2256
I am using C++ and Qt in my project and my problem is QObject::connect function doesn't connect signal to a slot. I have the following classes:
class AddCommentDialog : public QDialog
{
Q_OBJECT
public:
...some functions
signals:
void snippetAdded();
private slots:
void on_buttonEkle_clicked();
private:
Ui::AddCommentDialog *ui;
QString snippet;
};
A part of my Main window:
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void commentAddedSlot();
void variableAddedSlot();
...
private:
AddCommentDialog *addCommentDialog;
...
};
Ant the last dialog;
class AddDegiskenDialog : public QDialog
{
Q_OBJECT
public:
...
signals:
void variableAdded();
private slots:
void on_buttonEkle_clicked();
private:
Ui::AddDegiskenDialog *ui;
...
};
In the main window constructor i connect signals and slots:
addCommentDialog=new AddCommentDialog();
addDegiskenDialog=new AddDegiskenDialog();
connect(addDegiskenDialog, SIGNAL(variableAdded()), this, SLOT(variableAddedSlot()));
connect(addCommentDialog, SIGNAL(snippetAdded()), this, SLOT(commentAddedSlot()));
The point is my commentAddedSlot is connected to it's signal successfully, but commentAddedSlot is failed. There is the Q_OBJECT macros, no warning such as about no x slot. In addition to this, receivers(SIGNAL(snippetAdded())) gives me 1 but receivers(SIGNAL(variableAdded())) gives me 0 and i used commands qmake -project; qmake and make to fully compile. What am i missing?
Upvotes: 5
Views: 9678
Reputation: 7191
Quick look at your code gives no ideas what is your problem.
But, here are some moments:
You can control result of connect
function, so (from official documentation)
The function returns true if it successfully connects the signal to the slot. It will return false if it cannot create the connection, for example, if QObject is unable to verify the existence of either signal or method, or if their signatures aren't compatible.
Check if your objects (dialogs) creates well and pointers is not equal to NULL
.
ui_*
, moc_*
. And then recompile it.Good luck! And, please, give us feedback.
Upvotes: 3