1

I have asked a number of different questions now all regarding one main issue in my program and still not solved it at all, I'm using threading to keep my UI from locking up, but basically it still does because apparently you can't do UI stuff in threads.

So I've been told to use custom signals and slots (not that any examples were given).

So from the documentation I've read I came up with this code:

.h

signals:

void paint_signal(double x, double y);

.cpp

  connect(this,SIGNAL(paint_signal(double x, double y)), this, SLOT(PaintSomething(x,y)));

the Paintsomething function is within the same class as all of this....

thread:

*future2 = QtConcurrent::run(this, &GUI::paintAll);

paint all emits the paint_signal and passes 2 doubles

emit paint_signal(x, y);

but I get this error which I just don't understand at all

 connect: No such signal GUI::paint_signal(double x, double y)
4

2 回答 2

4
connect(this,
        SIGNAL(paint_signal(double, double)), 
        this, 
        SLOT(PaintSomething(x,y)));

删除参数名称,它应该可以工作。如果这个不起作用,这个将:

    connect(this,
        SIGNAL(paint_signal(double, double)), 
        this, 
        SLOT(PaintSomething(double,double)));

让我知道这是否适合你:)

更新

这个想法是您不能在线程中使用 UI,而是从线程向 UI 发出信号。因为这个答案可能会让你回到开始(可能是一个新问题)这里是一个如何从线程发出信号的工作示例:

QT 在线程中向 UI 发送信号

于 2013-04-25T09:24:47.810 回答
1

Floris Velleman 的回答是好的,但是通过使用新的信号槽语法,您可以在编译时捕获错误并摆脱多余的括号。

旧语法:

connect(this,
        SIGNAL(paint_signal(double, double)), 
        this, 
        SLOT(PaintSomething(double,double)));

新语法:

connect(this,
        &SenderClass::paint_signal, 
        this, 
        &ReceiverClass::PaintSomething);
于 2013-04-26T19:41:55.447 回答