Results 1 to 4 of 4

Thread: QML to Qt and back

  1. #1
    Join Date
    Jul 2012
    Posts
    3
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question QML to Qt and back

    Hi,

    How can I call a Qt public slot in the onTextChanged event of a QML-Text, that edits the source attribute of an QML-Image?

    What I basically would like to know is how to express the following in QML:
    Qt Code:
    1. QObject::connect(QML-Text, SIGNAL(onTextChanged()), SomeClass, SLOT(editSource());
    To copy to clipboard, switch view to plain text mode 

    The second challenge then would be to change the source attribute of the QML-Image.
    What I figured out by now is, that there's some QDeclarativeEngine class, however I don't really get how to implement it. Isn't there just some simple way to change attributes like it's possible with ui-files?
    Qt Code:
    1. ui->myLabel->setPixmap(pixmap);
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance,
    forty-two

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

    Default Re: QML to Qt and back

    It depends whether you want to do that from C++ or QML. If the former, then you need to access a particular object using the declarative engine. If the latter then you can for example use the Connections QML statement.
    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.


  3. #3
    Join Date
    Jul 2012
    Posts
    3
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QML to Qt and back

    Thanks for the quick reply,

    I would like to do the first task in QML and the second one in Qt/C++.

    If there's a class "MyClass" derived from QObject with a public slot called "editSource(QString text)", how would I connect this public slot from the class in QML?
    Qt Code:
    1. Text {
    2. id: myText
    3. onTextChanged: {
    4. // call the Qt slot from MyClass here
    5. }
    6. }
    To copy to clipboard, switch view to plain text mode 

    and how would I use QDeclarativeEngine in the Qt/C++ slot to change the source?

    How would that look in code?

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

    Default Re: QML to Qt and back

    You don't connect slots (or signals) to classes but rather to instances. So first you need an instance of the class and then you need to expose it to QML using QDeclarativeContext::setContextProperty(). Then it's just a matter of calling the instance's method in line #4 of your code snippet.
    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.


  5. The following user says thank you to wysota for this useful post:

    forty-two (1st July 2012)

Similar Threads

  1. can not go back to the previous window
    By xhsoldier in forum Qt Programming
    Replies: 1
    Last Post: 20th October 2010, 05:45
  2. Resizing back the widget
    By gruszczy in forum Qt Programming
    Replies: 6
    Last Post: 23rd November 2008, 10:14
  3. Back tracing asserts with gdb
    By ucomesdag in forum Qt Programming
    Replies: 8
    Last Post: 30th July 2007, 21:59
  4. drop image fly back
    By sreedhar in forum Qt Programming
    Replies: 5
    Last Post: 8th March 2006, 12:00

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.