Results 1 to 3 of 3

Thread: Connecting signal and slot fails in Symbian emulator

  1. #1
    Join Date
    Aug 2011
    Location
    Denmark
    Posts
    11
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Connecting signal and slot fails in Symbian emulator

    Im am trying to make a very basic Qt application that will use C++ for the data model and QML for the GUI. To my surprise it is not easy to find a good tutorial for this, so it's very much "trial and error". This is the code I've got so far:

    main.cpp:

    Qt Code:
    1. #include <QtDeclarative>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication app(argc, argv);
    6.  
    7. QDeclarativeView view;
    8. view.setSource(QUrl::fromLocalFile("qml/myapp/main.qml"));
    9. view.show();
    10.  
    11. QObject *root = view.rootObject();
    12.  
    13. QObject::connect(root, SIGNAL(quit()), &app, SLOT(quit()));
    14.  
    15. return app.exec();
    16. }
    To copy to clipboard, switch view to plain text mode 

    main.qml:
    Qt Code:
    1. import QtQuick 1.0
    2.  
    3. Rectangle {
    4. width: 360
    5. height: 360
    6. Text {
    7. text: "Hello World"
    8. anchors.centerIn: parent
    9. }
    10. signal quit()
    11. MouseArea {
    12. anchors.fill: parent
    13. onClicked: {
    14. quit();
    15. }
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    What it does is very simple: it shows a rectangle with the text "Hello World", and when you click in the rectangle the program quits. I know that this is exactly the same as the default app that Qt Creator creates when you choose to make a new "Qt Quick Application", but my app does it another and (I think) generally more useful way as I don't just start a QML program that sort of lives its own life but actually establish a connection between the C++ layer and the QML layer (with the signal/slot connection).

    Now to the problem. This runs without errors for the Desktop target. But if I choose the Qt Simulator as target it still runs, but I get this message in the console:

    Object::connect: No such signal QDeclarativeRectangle::quit()

    When I click the rectangle the app doesn't quit, and the console says:

    Signal QDeclarativeEngine::quit() emitted, but no receivers connected to handle it.

    Can someone please correct my code?

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Connecting signal and slot fails in Symbian emulator

    ***I didn't tried your code, but the problem is that there is no signal declared.

    i don't know QML but i think you should declare the signal, see this documentation page and also search the documentation - you should find references about what you want (or at least i think what you want makes sense - the QML isn't there to replace C++, it's just for quick UI "bling-bling" and it should be easy to connect with a C++ layer)

    LE: i saw the declared signal after i posted - it's strange that it won't work

  3. #3
    Join Date
    Aug 2011
    Location
    Denmark
    Posts
    11
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: Probably a configuration problem

    I have investigated this problem a little more myself, and it turns out that it's not my code that's bad. The problem is that Qt Creator doesn't put a new copy of main.qml in the build directory when I build for the emulator. When I took an updated copy of main.qml and placed it in the build directory it worked. So I guess the problem is in the configuration of my project.


    Added after 4 minutes:


    "or at least i think what you want makes sense - the QML isn't there to replace C++, it's just for quick UI "bling-bling" and it should be easy to connect with a C++ layer"

    - Exactly!
    Last edited by finngruwier; 7th August 2011 at 11:50.

Similar Threads

  1. Connecting signal and slot by name
    By grayfox in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2011, 09:00
  2. Replies: 3
    Last Post: 17th November 2010, 14:12
  3. Replies: 8
    Last Post: 13th July 2010, 14:08
  4. Replies: 2
    Last Post: 9th September 2009, 00:26
  5. Connecting signal to custom slot?
    By dbrmik in forum Qt Tools
    Replies: 2
    Last Post: 30th April 2009, 09:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.