Originally Posted by
Janek
1) I have 2 classes, first is MyForm, and second classTwo. MyForm have private object of type classTwo named objTwo - Is that a good idea? or better to create both of it in main.c as coexistent?
2) In MyForm constructor I try to connect SIGNAL from MyForm to SLOT from classTwo - it's not working, why?
connect(widget.buttonX, SIGNAL(clicked()), objTwo, SLOT(slotX(widget.edit->text())));
connect(widget.buttonX, SIGNAL(clicked()), objTwo, SLOT(slotX(widget.edit->text())));
To copy to clipboard, switch view to plain text mode
in SIGNAL() and SLOT() macros you give a signature of a method so the name of a method an type names of arguments, for example:
when you have class:
{
Q_OBJECT
public:
public slots:
void myMethod
(int a,
const QString str
);
};
class A : public QObject
{
Q_OBJECT
public:
A(QObject *parent = 0);
public slots:
void myMethod(int a, const QString str);
};
To copy to clipboard, switch view to plain text mode
and you want to connect some signal to the slot myMethod you have to write it like this:
SLOT(myMethod(int, QString))
To copy to clipboard, switch view to plain text mode
as you see just names of types, so you can't pass any arguments to slots in a connect() statement.
whats more you can't connect signal with no arguments (like clicked()) with a slot which has arguments, in general, you can't connect signal with less arguments then slot which you connect to.
So in your situation solution looks like:
1. Make a slot with no arguemnts, lets say slotClicked()
2. connect with signal clicked():
connect(widget.buttonX, SIGNAL(clicked()), objTwo, SLOT(slotClicked()));
connect(widget.buttonX, SIGNAL(clicked()), objTwo, SLOT(slotClicked()));
To copy to clipboard, switch view to plain text mode
3. in slotClicked() do something with that thing what you want.
4. but I dont know why you have a slot in different class to process text from a lineEdit() in different class... maybe make that slot in MyForm like this:
void MyForm::slotClicked()
{
objTwo->doSomething(widget.edit->text());
}
void MyForm::slotClicked()
{
objTwo->doSomething(widget.edit->text());
}
To copy to clipboard, switch view to plain text mode
that would be the easiest way.
P.S. Ohh and of course try reading some documentation and examples before trying to code, because all I said is written there with more examples and more clearly.
Bookmarks