Results 1 to 2 of 2

Thread: Need some help with connecting to a signal from coming from QML in c++.

  1. #1
    Join Date
    Mar 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Need some help with connecting to a signal from coming from QML in c++.

    Hi,

    to learn qt quick and understand better the basics, I made a hello world project in Qt Creator. Now I have thrown out the qmlapplicationviewer class in order to see the most simple functioning qml app and make sure I understand it. Now I get stuck here:

    Qt Code:
    1. // main.cpp
    2.  
    3. #include <QtGui/QApplication>
    4. #include <QDeclarativeView>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication app(argc, argv);
    9.  
    10.  
    11. QDeclarativeView view;
    12. view.setSource(QUrl::fromLocalFile("qml/untitled/main.qml"));
    13.  
    14. // QObject::connect( ( QObject* ) view.engine(), SIGNAL( quit() ),( QObject* ) &app, SLOT( quit() ) );
    15.  
    16. // ^--works | doesn't work --v
    17.  
    18. QObject::connect( view.engine(), SIGNAL( quit() ), &app, SLOT( quit() ) );
    19.  
    20. view.show();
    21.  
    22. return app.exec();
    23. }
    To copy to clipboard, switch view to plain text mode 

    When i try to build this I get the following error:

    \main.cpp:13: error: no matching function for call to 'QObject::connect(QDeclarativeEngine*, const char*, QApplication*, const char*)'

    qobject.h:198: note: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
    qobject.h:313: note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const


    Note that the commented out line works as expected... I would think the upcasting should be implicit... In no sample code in the documetation do I see the need for casts...
    Can anyone explain to me what is going on?

    The qml file is unchanged from how the wizard generated it:
    javascript Code:
    1. //main.qml
    2.  
    3. import QtQuick 1.0
    4.  
    5. Rectangle
    6. {
    7. width: 360
    8. height: 360
    9.  
    10. Text
    11. {
    12. text: "Hello World"
    13. anchors.centerIn: parent
    14. }
    15.  
    16. MouseArea
    17. {
    18. anchors.fill: parent
    19. onClicked:
    20. {
    21. Qt.quit();
    22. }
    23. }
    24. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 14th March 2011 at 10:20.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Need some help with connecting to a signal from coming from QML in c++.

    You're missing:
    Qt Code:
    1. #include <QDeclarativeEngine>
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Connecting Button with Quit-Signal
    By moatilliatta in forum Qt Programming
    Replies: 1
    Last Post: 11th October 2010, 16:19
  2. Connecting signal to custom slot?
    By dbrmik in forum Qt Tools
    Replies: 2
    Last Post: 30th April 2009, 09:28
  3. dynamic signal connecting
    By donglebob in forum Qt Programming
    Replies: 4
    Last Post: 19th November 2008, 09:58
  4. Replies: 4
    Last Post: 16th November 2008, 13:53
  5. Connecting signal to button
    By steg90 in forum Qt Programming
    Replies: 8
    Last Post: 13th December 2007, 10:37

Tags for this Thread

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.