我是 Qt 编程的新手。我掌握了发出信号并用插槽捕获信号的窍门,但是是否可以将插槽作为常规方法调用?
例如,在以下代码片段中:
class someClass{
..
..
//method
void emitsig1(int val)
{
emit sig1(val);
}
public signals:
void sig1(int a);
};
class someOtherClass{
..
..
public slots:
int onSig1(int a)
{
//some computation on a
return a;
}
};
int main(argc, char** argv){
..
..
someClass obj1 = new someClass();
someOtherClass obj2 = new someOtherClass();
int value = 10, result =0;
obj1.emitsig1(value);
QObject::connect(obj1, SIGNAL(sig1(int), obj2, SLOT(onSig1(int)));
int newvalue = 100;
//is it legal to do this, and if so, what value should I expect "result" to have?
result = obj2.onSig1(newvalue);