开发者

Problem using "connect()" within an iteration in qt4 with clicked() signals and using information from the iteration in the corresponding slot

For this, I'm programming in c++ using qt4 to design my interface.

In this program, I create a widget which spawns a (unknown) number QPushButtons depending on user input, thus I am creating them dynamically. At the moment of creation, I want to connect these buttons to a function that would need parameters that exist within the iteration of creating the buttons (for example, an int that would indicate a position in the a vector), yet I cannot do this due to the nature of signals/slots and the nature of the clicked() signal from the QPushButtons (it does not accept parameters).

The code looks somewhat like this:

vector<int> myVector

for(int i=0; i<user_input_number; i++){

    ...
    QPushButton *testingb4 = new QPushButton("Execute", this);
    connect( testingb4, SIGNAL( clicked() ), this, SLOT( customSlot() ) );
    ...

}

"customSlot" would need "i" to determine what element of my vec开发者_如何学运维tor I should access. How do I get solve this problem?


It seems you are looking for QSignalMapper. This may help you identify the source of click signals.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜