November 11, 2010

kibsoft kibsoft
Lab Rat
67 posts

Connecting QML signals with Qt slots.

 

Hi! I have such code:

  1. Item {
  2. signal itemClicked()
  3.  
  4.    MouseArea {
  5.         anchor.fill: parent
  6.         onClicked: itemClicked()
  7.    }
  8. }

Can I connect itemClicked() to slot in cpp application?

  1. QDeclarativeEngine *engine = new QDeclarativeEngine;
  2. QDeclarativeComponent component(engine, QUrl::fromLocalFile("qml/TestQML/TestQML.qml"));
  3. QObject *myObject = component.create();
  4. QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(myObject);
  5. qDebug()<<QObject::connect(item, SIGNAL(titleBarClicked()), &viewer, SLOT(showMaximized()));

connect() retuns true, but it doesn’t work.

5 replies

November 11, 2010

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1481 posts

see if this [wiki.forum.nokia.com] helps

November 12, 2010

mbrasser mbrasser
Lab Rat
452 posts

In the example the connect has titleBarClicked and the QML has itemClicked, is that just a typo? (if so, I don’t see obviously wrong — it looks like it should be working)

November 12, 2010

kibsoft kibsoft
Lab Rat
67 posts

In the example the connect has titleBarClicked and the QML has itemClicked, is that just a typo?

Yes, it’s a typo. But it doesn’t work :(

see if this helps

I need reverse connection..

November 15, 2010

mbrasser mbrasser
Lab Rat
452 posts

Hi,

Could you add a bug report on http://bugreports.qt.nokia.com with a small example to reproduce the problem?

Thanks,
Michael

November 15, 2010

kibsoft kibsoft
Lab Rat
67 posts

I’ve tried this feature in a simple project and it works. So the mistake somewhere in the my test app.

P.S. You can see this code example [fileconvoy.com].

Maybe you are know what’s wrong :)

 
  ‹‹ [Solved] QML in MFC app      Using QML the send post XML-requests ››

You must log in to post a reply. Not a member yet? Register here!