×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    80

    Using same C++ object in multiple qml file

    I need to use same C++ object as type in several QML files.

    in C++ main I have
    qmlRegisterType<ConnectionNotifier>("MyConnectionNotifier", 1, 0, "ConnectionNotifier");

    In qml I have
    import MyConnectionNotifier 1.0
    ...
    ConnectionNotifier
    {
    id: myBtConnotifier
    }

    If I do it in several qml file then it will create many C++ objects that I don't like. Can I pass my own element some how to other qml file that can use it?

    Any other options?

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Using same C++ object in multiple qml file

    hmmm if you make your c++ object a contextProperty in QML than you can use it any number of QML files. Please see the following code to understand what i want to say:

    Code:
    MyCplusplusClass m_MyCplusplusObject;
    declartiveView->rootContext()->setContextProperty("cplusplusobject",&m_MyCplusplusObject);
    now use cplusplusobject in any of the QML files.

  3. #3
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    80

    Re: Using same C++ object in multiple qml file

    Thanks, but if my cpp object emit signal how it can be handled in this case?

  4. #4
    Registered User
    Join Date
    Sep 2011
    Posts
    449

    Re: Using same C++ object in multiple qml file

    Hi,

    Please check this link , especially the Receiving signals part, it explains how signals in qml can be caught in c++ and also the same viceversa..

Similar Threads

  1. Use of multiple Active Object Callbacks
    By david4x in forum Symbian
    Replies: 14
    Last Post: 2010-08-04, 12:16
  2. Single http connection Object for multiple requests
    By J2me_champ in forum Mobile Java General
    Replies: 4
    Last Post: 2008-03-11, 11:42
  3. Multiple Obex object send via Bluetooth
    By jsstewart in forum Symbian
    Replies: 0
    Last Post: 2004-03-02, 22:57
  4. Replies: 0
    Last Post: 2003-08-29, 12:28

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×