mariomunera
mariomunera

Reputation: 323

Get target of cascades TouchEvent not working

I'm having problems trying to reach for the target of the Touch Event from BB10 cascades API. I have several containers, one below the other, and each one of them have the same Touch signal and slot assigned. Everything is being dynamically loaded from C++. So, in order to catch each touch event, I need to know which container triggered the event. I've read that I just need to use the TARGET property from the TouchEvent, but is not working and I dont know why. So I'm asking for help

Here's my code:

for (int i = 0; i < 10; i++) {
    QmlDocument *qml = QmlDocument::create("asset:///customComponents/TableRow.qml").parent(this);

    Container *passivesRow = qml->createRootObject<Container>();
    passivesRow->setProperty("labelTextOne", "Hello_" + i);

    bool res = QObject::connect(passivesRow,         
        SIGNAL(touch(bb::cascades::TouchEvent*)), this,
        SLOT(handleAccountTouch(bb::cascades::TouchEvent*)));

    Q_ASSERT(res);
    Q_UNUSED(res);

    myCurrentPageContainer->add(passivesScroll);
}

void PosicionConsolidada::handleAccountTouch(bb::cascades::TouchEvent* event) {
    if (event->touchType() == TouchType::Up) {
        qDebug() << "event catched";

        VisualNode *p = event->target();
        qDebug() << "object p: " << p->property("labelTextOne"); //Print nothing
    }
}

Everything else is working just fine. My list of Containers is being created fine with their respective texts. When I click one of them, the event is being catched successfuly. I also tried to cast the VisualNode object to Container and it didn't work either. Please help!.

Upvotes: 2

Views: 757

Answers (2)

Nishant Shah
Nishant Shah

Reputation: 1586

I would advice you an alternate approach which I used before. You can set objectName of control like this:

passiveRow->setObjectName("Hello_" + i");

QObject::connect(passiveRow, SIGNAL(touch(bb::cascades::TouchEvent*)), this,
        SLOT(handleAccountTouch(bb::cascades::TouchEvent*)));

& in SLOT using it you can know which control emitted the signal:

if (event->touchType() == TouchType::Up) {
    qDebug() << "object: " << QObject::sender()->objectName();
}

Here, sender() returns the control which emitted the signal.

Upvotes: 1

Benoit
Benoit

Reputation: 1921

In the API reference, there is no onTouch signal for the container.

On the contrary of other element like CustomControl

I do not know how your signal was successfully connected to your slot, but I guess that it was propagated from another component inside the container. So the target may be a Label or something else inside it.

Upvotes: 0

Related Questions