Determine the owner of the QML object attached to C++

I have a C++ class that I exposed to QML the usual way, and I'm tying to control QML. The problem is that it cannot be instantiated without setting. This is exactly the same that how LayoutUpdateHandler works, but I just can't understand how this class manages about who controls it is attached to.

The LayoutUpdateHandler constructor takes a pointer to a control as an argument. There is a constructor without arguments, but the docs say that if you use it, there is no way to define the target control later, do the actually useless LayoutUpdateHandler. Here is a typical use of QML:

Container {
   attachedObjects: [
      LayoutUpdateHandler {
         onLayoutFrameChanged: {
            // ---Do some stuff
         }
      }
   ]
}

Don't forget that LayoutUpdateHandler MUST have the target of control set when it is instantiated, it can be done later. Somehow the code above works, and the class instantiated with the parent container as the argument to the constructor object. Now I need to do the same thing with my own class, but I can't understand how to move on the instantiation of the parent control. No matter what I try the argument never happened and only the parameterless constructor is never called.

Anyone have an idea how it works and how I can get the QML to instantiate my class with the parent control passed as argument?

You're not the only dev who has tried to do.  I did it too and have been successful. You are on the right track.

Your class must inherit from BaseObject and override its classBegin() function.  This function will be called after your class has been instantiated, and her mother has been defined.

For example, I'm doing something like this:

class MyClass : public BaseObject
{
public:
    explicit MyClass();
    explicit MyClass(Control *target)
    virtual ~MyClass();
    virtual void classBegin();
private:
    void setTargetControl(Control *target);
};

MyClass::MyClass() : BaseObject(0)
{
}

MyClass::MyClass(Control *target) : BaseObject(target)
{
    setTargetControl(target);
}

MyClass::~MyClass()
{
}

MyClass::classBegin()
{
    BaseObject::classBegin();
    if(parent()) {
        Control *target = qobject_cast(parent());
        setTargetControl(target);
    }
}

MyClass::setTargetControl(Control *target)
{
    // Do your actual initialization here, which requres the target control.
    // In this case, the target control is the control that has this as part of
    // its attached objects block in QML-land
}

Tags: BlackBerry Developers

Similar Questions

  • What is the SQL to determine what are the table objects in the KEEP buffer pool?

    What is the SQL to determine what are the table objects in the KEEP buffer pool?

    Select owner, table_name

    from dba_tables

    where USER_TABLES = "KEEP."

    /

    David Fitzjarrell

  • Exponent of the QML C++ objects

    Hello

    I am new to qml and BlackBerry. What I want to do is basically described in this link:

    http://developer.BlackBerry.com/native/documentation/Cascades/dev/integrating_cpp_qml/index.html#exp...

    under "C++ objects exposing to QML.

    I did everything as described in the link. The point where I'm stuck is how to get out of here

    MyCppClass *cppObject = new MyCppClass();
    qml->setContextProperty("cppObject", cppObject);
    

    here

    Label {
      text: "Value of cppObject: " +  cppObject.value
    }
    

    When I know the code I need to create an instance of my class in the main.cpp file [MyCppClass * cppObject = new MyCppClass();] then setContextProperty to make it able to expose values to qml [qml-> setContextProperty ("cppObject", cppObject)]; and I can get the value by writing "cppObject.value" in my qml file.

    However, I get this result in the Console:

    ReferenceError: Can't find variable: cppObject

    I need to add something in the qml code so that the functions defined in C++ can be used in qml?

    I hope that these are enough information to help me here.

    All understood why I got this error.

    After you have created an instance of the class

    TMinutesContact *MinutesContact = new TMinutesContact();
    qml->setContextProperty("MinutesContact", MinutesContact);
    

    I need to set up

    AbstractPane *root = qml->createRootObject();
    
    app->setScene(root);
    

    to fill the contacts added with my duties of the class 'MinutesContact '.

    I don't know yet what exactly setScene does so that it now works.

    The App I'm trying is essentially over. The only thing missing was to implement you can get data of the qml code C++ objects. I am familiar with C++, but qml is new to me. So first of all, I had to struggle with all this code in this app.

    For all postal code containing in this app would be too much. And I don't know if I'm already good enough to choose just the necessary part that is important for my problem.

  • QML does not recognize the custom parameters of the signal object.

    Here is my sample code to test by passing an object custom c ++ qml.

    My custom object:

    class TestObject {}

    public:

    QString testString;

    TestObject() {testString = 'Hello' ;}

    };

    ...

    signals:

    void testErreur (TestObject * testObject);

    I declare it and send the singal of c ++

    Q_DECLARE_METATYPE (TestObject);

    ...

    qRegisterMetaType('TestObject');

    ...

    issue of testError (newTestObject ());

    and expect to receive the onTestError with the testObject setting

    He compiled and can receive the onTestError in qml slot, but it generates an error running this

    QMetaProperty::read: Unable to handle the kind of data not saved ' TestObject * "property"QDeclarativeBoundSignalParameters::testObject ".

    Asset:///testSreen.QML:123: error: unknown method parameter type: TestObject *.

    I did a couple of hours of looking on the forum but found no solution.  Hope that developers who have experience on the similar question can help out.

    Thank you

    Tyler

    Thanks Andrey,

    I changed it to Q_DECLARE_METATYPE(TestObject *); but still have the same error.

    The code that I showed is in fact to reduce the problem.  The actual design is to have a c ++ based customControl in the qml and I plan receive the signal and proceed the testObject to my c ++ customControl and release it there.

  • How to determine the number of pixels of an object in a digital photograph?

    Hello world. I want to determine the number of pixels in an object that is part of a digital photo. I use cameras to film of ice pieces, breaking with tide glaciers or ice cliffs. I want to know the size of the ice segment that capture my digital photos. I know that the width and height of the cliff of ice in metres already, so I thought that I could convert the equivalent of 1 pixel:? m is really what I want to do. This way, whenever I see a block of ice, breakup, I can pull up the photo, describe the piece, calculate how many pixels to fill the area of ice removed by piece break and convert into zone meters 2 - giving me my order of size. If anyone has any ideas on how to do really, I would appreciate it thanks so much community. I thought Photoshop or Fireworks might help me with this, Ricky

    Make your selection

    Select the histogram tab, and then click the symbol at the top right.

    Choose expanded view

    See this:

  • How to determine the owner of the current package?

    Leave a package (which is defined with the appellant's rights: AUTHID CURRENT_USER) I want to determine the owner of this package. (We intend to deploy the same code in multiple schemas).

    A solution would be to analyze the results of the DBMS_UTILITY.format_call_stack... to other ideas?

    Thank you
    Mike

    Here's some code which proves padders suggestion

    create or replace function WhoAreYou return VARCHAR2 as
    begin
      RETURN SYS_CONTEXT ('USERENV', 'CURRENT_USER');
    end;
    
    create or replace procedure WhoAmI
    AUTHID CURRENT_USER as
    begin
        DBMS_OUTPUT.PUT_LINE('I am [' || SYS_CONTEXT ('USERENV', 'CURRENT_USER') || '].');
        DBMS_OUTPUT.PUT_LINE('You are [' || WhoAreYou() || '].');
    end;
    
    grant execute on WhoAmI to scott
    
    exec bm.WhoAmI()
    
    I am [SCOTT].
    You are [BM].
    

    With this approach, it does not matter if we use a synonym or someother 'usurpation' method. The 'Stunt' tell you who he is.

    -Edited to complete the sentence
    I suggest you avoide trying to determine synonym against the table and all these complications.

    Published by: rp0428 on March 2, 2012 14:54

  • How can you determine the absolute path to a NetStream object created dynamically?

    We strive to implement a video captioning with a freeware component, ccforflash. This requires us to provide an absolute path or relative to our NetStream. How can we determine this path in Flash CS5 AS3?

    CCforFlashCS5 documentation:

    2. objects "name and path.

    Type the name and the path.  It is the name of the instance of the object with which CCforFlashAS3 will synchronize. It must be spelled correctly, since CCforFlashAS3 queries the object with this name for the synchronization information to synchronize subtitles. The path must also be included; be compared to the CCforFlashAS3 (i.e. this.parent) component or the absolute path of the main floor of the film (root)".

    I guess I understand your problem and accepts only a great way to identify a path to something compared to doing AS3 AS2.  I'll see if I can raise the interest of someone else in your ad that is a detective better than me.

    But if I can get stoopid for one minute and suggest trying something (I would try it)... If you have access to the code where is instantiated the NetStream object, just after he is given life, assign the instance to a variable, you have in the main timeline and use this variable (and the root timeline or a 'this' - reference database for path requirement) for your CCforFlashCS5 needs.

  • How can I determine the size of an object on a particular layer?

    Be it a rectangle, line, circle, etc. How to determine what size of an object on a particular layer?

    It depends on whether the object is on its own layer or not.

    If the object is on its own layer, then Ctrl click (cmd-click mac)

    on the thumbnail in the layers panel to make a selection around the

    object and the measures are visible in the info panel.

    If the object in question is not on it's own layer, then you can try to select

    with one of the selection tools like the magic wand or the Quick Selection tool and

    then read the info panel.

    For the hardest to select objects, you can try to place around the object guides

    and then make the selection.

    Make visible leaders (view > rulers) and you can drag the leaders out by clicking

    on the ruler and dragging a guide. After placing the guides use the rectangular

    Marquee tool and draw the selection on the guides (the selection must align with the guides.

    MTSTUNER

  • [CS2] [VB] How can I determine the type of object to a PageItem?

    I use InDesign CS2 and VBScript

    Loop to the bottom of the PageItems in a Page, I need determine the Type of object (TextFrame, group, GraphicLine... each process) and PageItem accordingly.

    Is there a method/function VBS wiil returns the Type of an object as a string or a value. Or what I need to check the existence/non-existence of a particular property associated with a particular object for this type?

    Alternatively, is there a JavaScript function that will do what I can call VBScript?

    For the record: TypeName is what you need.

    For example, when the cursor is planted in the text return TypeName (Ind.Selection (1)) 'PointInsertion.' When a text block is selected, it returns "TextFrame.

  • Error determining responsible for image size: the loading object is not sufficiently loaded to provide this information.

    Hello

    I am trying to load and image and determine its dimension immediately after loading.  I use a Loader object and check the width when the object of the loader's contentLoaderInfo Event.COMPLETE event is triggered...

    myLoader.contentLoaderInfo.addEventListener (Event.COMPLETE, onLoadComplete);

    Then:

    public void onLoadComplete(event:Event)

    {

    trace (myLoader.Width); 0

    trace (myLoader.contentLoaderInfo.Width); Error: The loading object is not sufficiently loaded to provide this information.

    }

    I tried something similar with the event of Event.INIT but same result.  Any ideas on the best way to solve this problem?

    Thank you!

    Moshe

    I think it's the answer to your question:

    trace(event.currentTarget.width);
    
  • Determine the hierarchy of objects based on the dependency.

    Hi all

    All packages in the database has invalidated due to a problem. You need to find the object hierarchy in oracle.

    Is it possible that I can the oracle object I the hierarchically based on the dependency?

    Is there a metadata table that stores this information?

    Example: Say, there are 10 packages. Package 1 depends on package 2 and 3-based package 2 and so on... and say package 10 is not dependent on.

    I need the list packages in the way below.

    Package of 10
    Package9
    Package8
    Package8
    :
    :
    :
    Package1

    Please let me know if you need any details.

    Thanks and greetings
    Nana Akkivalli.

    Something like this:

    select * from dba_dependencies where 1=1 and name ='PKGABC' and type = 'PACKAGE BODY'
    union all
    select * from dba_dependencies where 1=1 and referenced_name ='PKGABC' and type = 'PACKAGE BODY'
    

    Also look for
    deptree_fill in the oracle documentation

    http://docs.Oracle.com/CD/A57673_01/doc/Server/doc/ADG73/CH11.htm

    See you soon,.
    Manik.

  • Determine the name of class LVOOP? d ' a class of child...

    Hello

    I have a number of modules (classes) that inherit from a base class called "Module".  I have all these in an array of type 'Module', I would like to save some information of each of these modules, but I need to make the distinction between each module.

    Is there a way to determine the class name of the data cable?

    Can I use the flattened string Variant, but I was wondering if it had built in property for this node/function?

    Thank you
    Jonathan

    Examples of joint:

    Malkieri,

    There is no generation in function that does exactly what you are looking for, but you can use the 'Get LV class Path' VI to return the *.lvclass of an object path given.  Using this way, you can either parse the name, or you can use Server VI to get the name of the class, as shown in the picture as an attachment.

    Chris M

  • How can I determine the position of the mouse in a 2D image control

    I have an app where I would like the user to be able to interact with objects in a 2D image control with the mouse.  To do this, I need to translate between the screen coordinates, which are transmitted with the events of mouse and in the control of 2D image.

    The problem that I am running is that I can't find a way to determine the screen coordinates of the top left corner of the drawing/client of the 2D image control area.  I tried to use the 'Position' of the image control property, but this results in a mismatch because of the difference between the upper-left corner of the image control (including the label, etc.) and the upper left corner of the drawing area.  See attached VI.

    Does anyone know how to get the coordinate of the screen from the corner of the drawing of the control of the photo area?

    Mark Moss

    I tend to use the mouse in the image control property to get the position.  Deals with things like the passage of origin for you.

  • How to determine the strict reference to the table of waveform

    Hello

    I want to change the properties of a waveform by programming. I used to get all references maps of waveform a function of range in my script VI VI. Then I typecasted references to more specific class (strict-single track) after this trial I was able set properties such as data history. Everything works fine but if I add a graphic that is multiplot, that this approach does not work.

    The problem is that in the table of references, there is reference to a graph in multiplot waveform, and this reference is not possible typcast to the more specific category (strict-single parcel).

    My question is: how to determine if the reference in the table is matching the proper waveform (single or multiplot) charts.

    In the VI attached is a code that demonstrates my problem.

    Thanks a lot for the replies

    Jan

    Thank you for advice. VI point 2 from your answer, I created and it works. The solution is attached.

    If I understand it correctly. I need to know the type of chart to come.

    My first idea was to create a VI in Drop that initializes all the graphics of VI on chart type independently.

    But this solution is fine because I will only use graphics-single plot and multiplot(two elements).

    Thank you

    Jan

  • determine the Center and the radius of the circles

    I want to determine the Center and the radius of the circles in the attached photo.

    I tried to use "IMAQ Fit circle 2", but I didn't know how to use the vi.

    Is there anyone can give me an example how to use "IMAQ Fit circle 2" for the image as an attachment?

    Or tell me any other method to determine the Center and the RADIUS.

    This example not found?

Maybe you are looking for