signal of QListWidget doesn't work
Hello,
First of all forgive me my bad English and please keep in mind I'm a complete newbie to C++. I did some coding for a while in 'Gambas', that's like Visual Basic but for Linux.
Up to now it goes fine with Qt but I do have one problem I can't solve ...
The GUI of my first program is made with designer and has amongst several buttons and lineEdits also a ListWidget.
This ListWidget does not emit signals, all other widgets do, they work fine.
Here's some code I use to emit the signal:
connect(listWidget, SIGNAL(itemActivated(QListWidgetItem * item)), this, SLOT(enableDeleteButton()));
Signal itemClicked() doesn't work neither....
As the function enableDeleteButton() says it will enable a button I can use to remove items from the ListWidget.
Anyone an idea what I'm doing wrong?
Thanks.
Vito
Re: signal of QListWidget doesn't work
You must not put parameter names to the connect statement. It should be:
Code:
connect(listWidget,
SIGNAL(itemActivated
(QListWidgetItem*)),
this,
SLOT(enableDeleteButton
()));
Re: signal of QListWidget doesn't work
Quote:
Originally Posted by
jpn
You must not put parameter names to the connect statement. It should be:
Code:
connect(listWidget,
SIGNAL(itemActivated
(QListWidgetItem*)),
this,
SLOT(enableDeleteButton
()));
Yes, this was the solution, thanks ... but how do I know what item is selected for deletion if I can't put it in a parameter? Or are there other ways?
Thank you for your help.
Vito
Re: signal of QListWidget doesn't work
Re: signal of QListWidget doesn't work
Quote:
Originally Posted by
vito49
Yes, this was the solution, thanks ... but how do I know what item is selected for deletion if I can't put it in a parameter? Or are there other ways?
Thank you for your help.
Vito
you can use the following syntax:
This way, in the enableDeleteButton() function, u can access the current item from the argument.
An alternate solution is to have the button you want to enable accessible in the enableDeleteButton() function and use currentItem () to get the current item.
To make the button accesible, declare the button in the class itself (as a private variable), then you'll be able to access it in the enableDeleteButton() function.
Re: signal of QListWidget doesn't work
Quote:
Originally Posted by
montylee
you can use the following syntax:
This way, in the enableDeleteButton() function, u can access the current item from the argument.
An alternate solution is to have the button you want to enable accessible in the enableDeleteButton() function and use currentItem () to get the current item.
To make the button accesible, declare the button in the class itself (as a private variable), then you'll be able to access it in the enableDeleteButton() function.
I can't figure it out .. well, I'm new to C++ and Qt ;)
I changed a few things ...
Code:
{
msgDelete.setText("item is going to be removed");
int msg=msgDelete.exec();
listWidget->removeItemWidget(item);
}
But the item is not removed ... probably I'm using the wrong code..
I read that QListWidget is read-only by default, I can't find out if that's true or how to change that if that's the case.
Don't mind the MessageBox in the function, I still have to implement a second button so I can choose to delete or to leave the item. The delete button I previously used is no longer valid.
Thanks for your help.
Re: signal of QListWidget doesn't work
Item widgets are widgets laid on top of items. QListWidget::removeItemWidget() removes an item widget, but leaves the actual item intact. Just delete the item to remove it from the list.
Re: signal of QListWidget doesn't work
Quote:
Originally Posted by
jpn
Just delete the item to remove it from the list.
That's my problem ... I can't find any member of QListWidget that removes/deletes an item. Unless I don't understand the English text of course ... sorry for that.
Re: signal of QListWidget doesn't work
Use the C++ delete operator:
:)
Re: signal of QListWidget doesn't work
Quote:
Originally Posted by
jpn
Use the C++ delete operator:
:)
Yep, that was it ... as easy as that.
Well I do have to learn a lot, but I'm a good student (I think) :D
Many thanks for your help.
Re: signal of QListWidget doesn't work
Before delete, you can delete the item by using the following API:
This API actually removes the item from the list widget and returns the item. After calling this API, you should call delete on the item which was returned by the above API.