Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4344084
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:50:45+00:00 2026-05-21T11:50:45+00:00

This page shows how to call C++ functions from within QML. What I want

  • 0

This page shows how to call C++ functions from within QML.

What I want to do is change the image on a Button via a C++ function (trigger a state-change or however it is done).

How can I achieve this?

UPDATE

I tried the approach by Radon, but immediately when I insert this line:

    QObject *test = dynamic_cast<QObject *>(viewer.rootObject());

Compiler complains like this:

    error: cannot dynamic_cast '((QMLCppBinder*)this)->QMLCppBinder::viewer.QDeclarativeView::rootObject()' (of type 'struct QGraphicsObject*') to type 'class QObject*' (source is a pointer to incomplete type)

In case it is relevant, QMLCppBinder is a class that I try to build to encapsulate the connections from several QML pages to C++ code. Which seems to be trickier than one might expect.

Here is a skeleton class to give some context for this:

    class QMLCppBinder : public QObject
    {
        Q_OBJECT
    public:
        QDeclarativeView viewer;

        QMLCppBinder() {
            viewer.setSource(QUrl("qml/Connect/main.qml"));
            viewer.showFullScreen();
            // ERROR
            QObject *test = dynamic_cast<QObject *>(viewer.rootObject());
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T11:50:46+00:00Added an answer on May 21, 2026 at 11:50 am

    If you set an objectName for the image, you can access it from C++ quite easy:

    main.qml

    import QtQuick 1.0
    
    Rectangle {
        height: 100; width: 100
    
        Image {
            objectName: "theImage"
        }
    }
    

    in C++:

    // [...]
    
    QDeclarativeView view(QUrl("main.qml"));
    view.show();
    
    // get root object
    QObject *rootObject = dynamic_cast<QObject *>(view.rootObject());
    
    // find element by name
    QObject *image = rootObject->findChild<QObject *>(QString("theImage"));
    
    if (image) { // element found
        image->setProperty("source", QString("path/to/image"));
    } else {
        qDebug() << "'theImage' not found";
    }
    
    // [...]
    

    → QObject.findChild(), QObject.setProperty()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement this JSF page with pagination and sorting. Unfortunately Netbeans shows
The example on this page only shows Groovy assertions without parentheses. assert a !=
On this page: http://www.arvag.net/old/smsbox.de/ when you hover over Informationen and Über ins, it shows
When trying to get next activities it shows this error: This page contains the
I have a page that shows statistics for users, this cannot be cached because
Can anyone help me with reversing this PHP page navigation? Current script setting shows
I have this line below that shows a link to go the next page
Firefox has this nice find-a-text-on-the-page dialog, which is non-modal and shows up at the
I have a page with an unordered list built like this: <ul id='shows'> <div
In my web page i used a gridview. In this gridview it shows a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.