Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [SOLVED]- QWebKit - connect a web button to a Qt slot

    General and Desktop
    1
    2
    670
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      maximus last edited by

      I am trying to follow the tutorial" here":http://qt-project.org/doc/qt-4.8/webkit-imageanalyzer.html

      In my mainWindow, I create an custom Object
      @settingsObject = new SettingsObject(this); @

      My QWebView is connected to to this slot :
      @ QObject::connect(ui->webView_settings->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
      this, SLOT(addJSObject()));
      void MainWindow::addJSObject() {
      ui->webView_settings->page()->mainFrame()->addToJavaScriptWindowObject(QString("settingsObject"), settingsObject);
      }@

      My web button :
      normal button with onclick = analyzeImages()

      My J_avascript :
      @
      function connectSlots()
      {
      if ( !connected ) {
      connected = true;
      settingsObject.foundSensorHr.connect(this, found);
      }
      }

      function found() {

      window.alert("found!");
      }

      function analyzeImages()
      {
      connectSlots();
      settingsObject.searchSensorHr();

      // window.alert("sometext"); ///get called, problem is not here
      }
      @

      My custom object "SettingsObjects"

      @#ifndef SETTINGSOBJECT_H
      #define SETTINGSOBJECT_H

      #include <QObject>

      class SettingsObject : public QObject
      {
      Q_OBJECT

      public:
      explicit SettingsObject(QObject *parent = 0);

      public slots:
      void searchSensorHr();

      signals:
      void foundSensorHr();
      };
      #endif // SETTINGSOBJECT_H@

      .cpp

      @/// Slot
      void SettingsObject::searchSensorHr() {

      qDebug() << "search Sensor Hr";
      
      emit foundSensorHr();
      

      }
      @

      However when I click the button, the Qt slot doesn't seem to be called (nothing is printed in the console).
      I have tested the javascript with an alert and it's called, so there must be a problem with the link from the button to the Qt slot. Will pay you 5000 dogecoins if you help me find the problem! :)


      Free Indoor Cycling Software - https://maximumtrainer.com

      1 Reply Last reply Reply Quote 0
      • M
        maximus last edited by

        Update: I can get the slot to fire if I comment :
        connectSlots() in analyseImage();

        still investigating, look promising

        Edit: Woot got it, Forgot to initialize the value of the variable "connected" in the script
        connected = false;

        Thanks Qt this thing is awesome redoing all my interface with QWebKit so much easier


        Free Indoor Cycling Software - https://maximumtrainer.com

        1 Reply Last reply Reply Quote 0
        • First post
          Last post