0

I have tried everything I know of (which admittedly isn't very much) and searched google for about an hour but I just can't figure this out.

I have a class called PlaceHolder, which inherits from QListWidgetItem. I want to be able to register double clicks on this, so I tried using the signal itemDoubleClicked(QListWidgetItem*) on the QListWidget. However, when I do that, I need a slot that has the same arguments. This would not be a problem if I didn't need to access the functions/variables of the PlaceHolder that was clicked, but I do.

If there's anything else you need to know to help me then please feel free to ask. Thank you for any time and effort you spent on this problem.

KFox
  • 1,166
  • 3
  • 10
  • 35

1 Answers1

1

I'm a bit unclear on your question. Is the problem that you have a QListWidgetItem* instead of a PlaceHolder*?

Try:

void MyWidget::handleDoubleClickSlot(QListWidgetItem* item)
{
    PlaceHolder* placeHolderItem = qobject_cast<PlaceHolder*>(item);

    if (placeHolderItem == NULL)
    {
        // oops, not a PlaceHolder item
        return;
    }

    placeHolderItem->myAwesomePlaceHolderMethod();
}

As shown, it will return NULL if the item is somehow not a PlaceHolder object.

darron
  • 4,284
  • 3
  • 36
  • 44
  • Thanks for the quick response, but I get the error message: `no matching function call to 'qobject_cast(QListWidgetItem*&)'`. What part have I messed up on? – KFox Apr 16 '13 at 19:41
  • Hmm, did you enter it as above with angle brackets first around "PlaceHolder*", then parenthesis afterward? You need "#include " included from something, but in widgets something should have certainly included that... – darron Apr 16 '13 at 20:21
  • Thanks, I forgot the parentheses around item. My bad. – KFox Apr 16 '13 at 20:30