Hi. I'm new to QT and I have a good-programming-style-type problem. I want to connect 2 objects. Until now , i wrote some simple applications , and connected objects that one contains another. For example:
{
private:
public:
c()
{
...
connect(button,SIGNAL(signal()),this,SLOT(slot()));
...
}
};
class c : public QWidget
{
private:
QPushButton *button;
public:
c()
{
...
connect(button,SIGNAL(signal()),this,SLOT(slot()));
...
}
};
To copy to clipboard, switch view to plain text mode
And it was simple and easy.
But what if i want to connect to objects that none of them is containing another ? In "connect" i have to pass pointers to sender and reciever. Should I pass the pointer to another object in a constructor ? For example:
{
...
public slots:
void slot();
...
};
{
...
signals:
void signal();
public:
ObjectB(ObjectA *p)
{
...
connect(this,SIGNAL(signal()),p,SLOT(slot()));
...
}
};
class ObjectA : public QWidget
{
...
public slots:
void slot();
...
};
class ObjectB : public QWidget
{
...
signals:
void signal();
public:
ObjectB(ObjectA *p)
{
...
connect(this,SIGNAL(signal()),p,SLOT(slot()));
...
}
};
To copy to clipboard, switch view to plain text mode
Is that a good way to do that ? It works, but I believe something is wrong with that. What if i want to connect one object with twenty anothers , so i neet do pass 20 pointers in a constructor ?
Bookmarks