How do I get my JS running?
I am trying to execute my JS when ever any signal is emiited from Qt code. I am using QgraphicsWebview, but I am unable to figure out how can I do this. I have QPushbutton signal connected in my JS but when I click button my JS function does not get called. I am sure I am missing something in the code but can not figure out, can any one please point me to some document or example?
The official documentation is http://doc.qt.nokia.com/4.7/qtwebkit-bridge.html . If it still doesn't work, can you paste a small, compilable example that does not work?
Let me try to do it the way this documentation says.
I will comeback again if it does not. Hopefully It will solve the problem:)
and in my htm, i m calling mywidget.mysignal.connect(this,myJSFunction);
But it is not calling myJSFunction(), I can see if I call slot of my object it works,
mywidget.updateSlot(), I can see my debug is being printed there but signal which is being emiited from constructor is not connecting.
Here is my example:
class GrphWidget : public QGraphicsWidget
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
// emit mySignal2();
void GrphWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
QGraphicsWidget::paint(painter, option, widget);
class MyWebPage : public QWebPage
MyWebPage(QObject * parent = 0);
QObject * createPlugin(const QString & classid,const QUrl & url, const QStringList & var,const QStringList & values);
MyWebPage::MyWebPage(QObject * parent)
QObject * MyWebPage::createPlugin(const QString & classid,const QUrl & url,const QStringList & var,const QStringList & values)
if (classid == "Object")
qDebug()<<" MyWebPage::createPlugin called";
GrphWidget *myobj = new GrphWidget;
QString name = values.at(var.indexOf("name"));
int main(int argc, char *argv)
QApplication app(argc, argv);
QGraphicsScene myscene = new QGraphicsScene(0, 0, 600, 400);
myview.setGeometry(QRectF(0, 0, 600, 400));
my JS file:
alert("I got my signal");
If singals are connected then it should show my message box.
<object type="application/x-qt-plugin" classid="Object" name="myObject" height="40"
<object type="application/x-qt-plugin" classid="Object" name="myObject2" height="40"
if you paste code, please surround it with @. Then it is displayed as code. You also find buttons over the edit area to insert these tags. I did it for your last post. Thanks.
Thank you Gerolf, I am very very new to this, today only I joined this Network, I did not know how to paste the code. Thank you for doing this for me.
Your welcome, an welcome on DevNet. I hope, you enjoy it and find the answers, you are searching.
Finally I got it working. Looks like signals slots were not being initialized properly. I put One alert in JS and every thing worked. So finally I did my connection at the end when loading of the page was done, so I added onload=myfunction() in body element and put all my connection there and every thing worked.