Results 1 to 20 of 23

Thread: Return QObject undefined

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2007
    Posts
    78
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Return QObject undefined

    If I pass an object to a QML and that object in turn grabs another object I error out with the following:

    "code example/main.js:4: TypeError: Result of expression 'failedObject' [undefined] is not an object."

    Now if I change line 16 in object1.h (and of course its matching function in object1.cpp) to QObject the script will convert it fine and I will not have any errors. The problem with this is I then have to qobject_cast when using the function internally in the c++ code. This casting internally just to get it to be recognized correctly in the script feels wrong to me.

    Since my class inherits QObject I was under the impression I should not have to use qRegisterMetaType. It appears to be registered correctly since it knows how to cast it in the script when it is passed as a QObject.

    I am confused on why I must use QObject and let the script auto cast it and I cannot reference my class directly if it is already registered. Also not sure if casting my class internally will have a performance hit or is just bad form?

    Short Question: Why cant I reference a return object using my specific class identifier in a script?

    I attached a very small code example that will show specifically what the problem is.
    Attached Files Attached Files

Similar Threads

  1. undefined reference to `QUiLoader::QUiLoader(QObject*)'
    By ashukla in forum Qt Programming
    Replies: 7
    Last Post: 7th October 2011, 18:05
  2. Return value to QList
    By lyucs in forum Newbie
    Replies: 7
    Last Post: 16th October 2009, 02:31
  3. undefined reference to QObject
    By hcerny in forum Qt Programming
    Replies: 2
    Last Post: 2nd May 2008, 16:55
  4. Replies: 1
    Last Post: 31st October 2007, 14:14
  5. Replies: 1
    Last Post: 18th June 2006, 10:12

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.