Results 1 to 4 of 4

Thread: Pointer in Q_PROPERTY

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Pointer in Q_PROPERTY

    Hello,

    I have a problem accessing pointer property, defined as Q_PROPERTY, in JavaScript using QWebKit - here is a simple example:

    Qt Code:
    1. // MyObject.h
    2. class MyObject : public QObject {
    3. Q_OBJECT
    4.  
    5. public:
    6. Q_PROPERTY (QString* version READ getVersion)
    7.  
    8. QString* getVersion();
    9.  
    10. QString* version;
    11.  
    12. public slots:
    13. void populateJavaScriptWindowObject();
    14. };
    15.  
    16. // MyObject.cpp
    17. MyObject::MyObject() {
    18. qRegisterMetaType<QString*>("QString*");
    19.  
    20. version = new QString("1.0");
    21.  
    22. connect(app->getWebView()->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(populateJavaScriptWindowObject()));
    23. }
    24.  
    25. QString* MyObject::getVersion() {
    26. return version;
    27. }
    28.  
    29. void MyObject::populateJavaScriptWindowObject() {
    30. app->getWebView()->page()->mainFrame()->addToJavaScriptWindowObject("my", this);
    31. }
    To copy to clipboard, switch view to plain text mode 

    In JavaScript I should get following object:

    Qt Code:
    1. my: {version: "1.0"}
    To copy to clipboard, switch view to plain text mode 

    but instead I get:

    Qt Code:
    1. my: {version: ""}
    To copy to clipboard, switch view to plain text mode 

    I will be grateful for any help, thanks!

    Regards,
    Piotr
    Last edited by pkorzeniewski; 18th September 2012 at 23:25.

Similar Threads

  1. Q_property
    By micky in forum Qt Programming
    Replies: 2
    Last Post: 23rd April 2012, 18:51
  2. Replies: 1
    Last Post: 4th December 2010, 17:20
  3. Help with Q_PROPERTY with object pointer
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2009, 17:31
  4. Why and when to use Q_PROPERTY
    By Vanir in forum Qt Programming
    Replies: 4
    Last Post: 22nd November 2007, 09:25
  5. How to Use Q_PROPERTY
    By mitesh_modi in forum Qt Programming
    Replies: 7
    Last Post: 20th June 2006, 14:49

Tags for this Thread

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.