HOWTO: Use the contextual action with ListView in C++

Hello

I need your advice and the best way to manage the user in the context menu action, linked to a ListItem (or the MultiSelectActionItem)

My skeleton of ListView is defined in QML. In C++, I create and fill in ListView. ListView can be instancied multiple times (each with its own data model). So for each ListView, I get the same action of context.

Now, how to manage the action trigger signal. Sample for ListItem delete action, I can not connect a slot to the signal of ListItem. Otherwise, I have to do for each ListItem! I think that this is not the right way.

I looked at the bucket sample. Stocks are managed directly by the datamodel.

The second point is that the action item process is long and regular through the event of Qt. loop (and of course the content list may change before the end of the process).

Another solution could be: QML send a signal custom ListView object (and not the ListItem).

Nicolas

I see what you mean about Battambang: there are a series of action applied to each element.

In many cases, it may be wiser to join acts to list.  I suggest something along these lines:

Addition of stampcollector main.qml in the ListView after the ListItemComponents:

                contextActions: [
                    ActionSet {
                        ActionItem {
                            objectName: "ooglyAction"
                            title: "oogly"
                        }
                        ActionItem {
                            objectName: "booglyAction"
                            title: "boogly"
                        }
                        DeleteActionItem {
                            objectName: "deleteAction"
                            title: "Delete"
                        }
                    }
                ]

In stampcollectorapp.cpp:

(a) in the constructor:

    ActionItem* action = nav->findChild("ooglyAction");
    if (action)
        connect(action, SIGNAL(triggered()), this, SLOT(onListActionOogly()));
    action = nav->findChild("booglyAction");
    if (action)
        connect(action, SIGNAL(triggered()), this, SLOT(onListActionBoogly()));
    DeleteActionItem* daction = nav->findChild("deleteAction");
    if (daction)
        connect(daction, SIGNAL(triggered()), this, SLOT(onListActionDelete()));

(although you can use the same signal for all the actions non - handler remove if you want to turn on the text of action in Manager)

(b) methods as:

void StampCollectorApp::onListActionOogly()
{
    qDebug() << "Here I am: oogly!";
    qDebug() << sender();
}
void StampCollectorApp::onListActionBoogly()
{
    qDebug() << "Here I am: Boogly!";
    qDebug() << sender();
}
void StampCollectorApp::onListActionDelete()
{
    qDebug() << "Here I am: Delete!";
    qDebug() << sender();

    DeleteActionItem* action = dynamic_cast(sender());
    if (action == 0)
    {
        qDebug() << "Not expected type";
        return;
    }
    qDebug() << "Yes, found!";

    QObject* parent = action->parent(); // get ActionSet
    if (parent != 0) parent = parent->parent();
    if (parent == 0)
    {
        qDebug() << "No parent!";
        return;
    }
    const QMetaObject* m = parent->metaObject();
    if (m == 0)
    {
        qDebug() << "No metaobject!";
    }
    qDebug() << m->className();
}

In other words, use sender()

Stuart

Tags: BlackBerry Developers

Similar Questions

Maybe you are looking for

  • Product recovery / disk drive not recognized

    I am trying to achieve a waste product on a Toshiba Satellite running Windows Vista. I followed the instructions provided with the product recovery disc (insert the disc, restart your computer, press F12). While the recovery was then frozen at about

  • What version of Bootcamp need me?

    Hello I have a Macbook Pro end 2013/mid 2014 (model A1398) running Windows 7. I got a pair of headphones Bluetooth Jaybird X 2 for Christmas that I tried to go to work. I have completely failed.  I am able to pair the headset but there are about four

  • HP elitebook 8460p: drivers needed

    My HP elite book 8460p will not get online and I have no idea why, but the WiFi connection seems fine. I am aware that miss me three pilots in the section 'other' devices... I believe that those who might be the reason, but I don't know and because I

  • Cannot install Service Pack 3

    I tried several times to install Service Pack 3.  I have XP Professional.  The error is "not enough disk space on C:\Windows\$NtServicePackUninstall$ etc etc and he wants an another 4 MB of space."  I have about 24Gig of space and deleted several tim

  • Remove the symbol of security on the desktop icon shield

    Greetings. Is it possible that I can remove security shield symbol that comes with the desktop icon or prevent before installing any program... As far as I know, there are forums that suggesting turning out of control (UAC) user account would solve t