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

  • SEARCH
  • Home
  • 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 8832881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:38:31+00:00 2026-06-14T08:38:31+00:00

I am developing an application in QT and QML to access some XML data

  • 0

I am developing an application in QT and QML to access some XML data and display the results.

The XML is downloaded / parsed from C++ and this works fine.
I have a QML application designed to display the custom layout and that also works fine.

To make the app look more polished I have an initial “splash screen” that’s displayed whilst the C++ side completes the initial download / parse, I have created a property inside the main QML view to represent the current application “state” so I can swap to the correct screen when the data is ready.

Main.qml

Item
{
   id: mainScreen
   width: 800; height: 600;   
   property int activeState: 0       // This controls what screen is displayed

   Item 
   {
       // screen layout .. removed .. 
   }
}

The C++ code is generated by the QT creator app wizard and is based around the basic QmlApplicationViewer class.

I’ve read (and re-read) the online QT docs and supposedly all I have to do to access the individual properties of mainScreen is to call the findChild<QObject *> method of the application viewers rootContext() to return a QObject pointer to the mainScreen instance and then call the setProperty method like so.

QObject *mainView = ROOT_CONTEXT->findChild<QObject *>("mainScreen");

qDebug("mainView = %08X",(uint)mainView);

if(mainView)
{
    mainView->setProperty("activeState",1);
}
else
    qDebug("Unable to find the mainScreen QML object");

Where ROOT_CONTEXT is defined elsewhere as

QDeclarativeContext *ROOT_CONTEXT;
QDeclarativeEngine  *ROOT_ENGINE;
QGraphicsObject     *ROOT_OBJECT;

void QmlApplicationViewer::createMyApplication(void)
{
    ROOT_CONTEXT = this->rootContext();
    ROOT_OBJECT  = this->rootObject();
    ROOT_ENGINE  = this->engine();

    pMyApplication = new MyApplication(this);
}

and void QmlApplicationViewer::createMyApplication(void) is called after the main QML file has been setup ie

QmlApplicationViewer viewer;

viewer.setMainQmlFile(QLatin1String("main.qml"));
viewer.showExpanded();
viewer.createMyApplication();

BUT…

The problem I’m running into is that that the value returned from findChild<QObject *>("mainScreen"); is always NULL. I’ve tried enumerating through the hierarchy of objects in my QML file using the following code

QList<QObject*> list = ROOT_OBJECT->findChildren<QObject*>();

qDebug("list = %d",list.count());
int i;

for(i=0;i<list.count();i++)
{
    QObject *obj = list[i];

    qDebug() << "Object" << i << obj->objectName();
}

and I get a list of ~120 items but they all have a blank string (“”) for their name.

Looking back at the QT docs all the examples seem to suggest creating the individual parts by hand (ie creating an instance of QDeclarativeEngine, QDeclarativeComponent and QDeclarativeItem) and linking them together instead of using the QApplicationViewer class as shown on this blog entry http://xizhizhu.blogspot.co.uk/2010/10/hybrid-application-using-qml-and-qt-c.html, but I’d much rather stick with the code I’ve already written.

Can anyone please help and suggest where I’m going wrong or point me in the direction where I can find a “simple” example of being able to change a property of an Item in a QML file from C++.

Many (many) thanks in advance.

Jon…

  • 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-06-14T08:38:32+00:00Added an answer on June 14, 2026 at 8:38 am

    Main.qml should be

    Item
    {
       id: mainScreen
       objectName: "mainScreen"
       width: 800; height: 600;   
       property int activeState: 0       // This controls what screen is displayed
    
       Item 
       {
           // screen layout .. removed .. 
       }
    }
    

    You were missing the objectName: “mainScreen”, that’s how findChild<>() finds it’s children.

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

Sidebar

Related Questions

im developing application for ios5.im using core data as data storage.i have to display
Thanks for your time. I am developing application using PHP. In this for some
iam developing one application.In that i need to get the music files from the
I am developing application. In that i am populating spinner from the database. I
I'm developing application that will read messages from IMAP server.. what would you recommend
I'm developing application in WPF but some components are written using WinForms. I wan't
I'm developing application using VC++ 6. I have a 3rd party DLL. This library
I developing application which using geo-location. Should i ask user right for this when
I'm developing application which need access to user's facebook account. It is working, but
I'm developing application for android by using flex. That app should read sms from

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.