Hello,
I have a problem accessing pointer property, defined as Q_PROPERTY, in JavaScript using QWebKit - here is a simple example:
// MyObject.h
Q_OBJECT
public:
Q_PROPERTY (QString* version READ getVersion
)
public slots:
void populateJavaScriptWindowObject();
};
// MyObject.cpp
MyObject::MyObject() {
qRegisterMetaType<QString*>("QString*");
connect(app->getWebView()->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(populateJavaScriptWindowObject()));
}
return version;
}
void MyObject::populateJavaScriptWindowObject() {
app->getWebView()->page()->mainFrame()->addToJavaScriptWindowObject("my", this);
}
// MyObject.h
class MyObject : public QObject {
Q_OBJECT
public:
Q_PROPERTY (QString* version READ getVersion)
QString* getVersion();
QString* version;
public slots:
void populateJavaScriptWindowObject();
};
// MyObject.cpp
MyObject::MyObject() {
qRegisterMetaType<QString*>("QString*");
version = new QString("1.0");
connect(app->getWebView()->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(populateJavaScriptWindowObject()));
}
QString* MyObject::getVersion() {
return version;
}
void MyObject::populateJavaScriptWindowObject() {
app->getWebView()->page()->mainFrame()->addToJavaScriptWindowObject("my", this);
}
To copy to clipboard, switch view to plain text mode
In JavaScript I should get following object:
my: {version: "1.0"}
my: {version: "1.0"}
To copy to clipboard, switch view to plain text mode
but instead I get:
my: {version: ""}
my: {version: ""}
To copy to clipboard, switch view to plain text mode
I will be grateful for any help, thanks!
Regards,
Piotr
Bookmarks