Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]- QWebKit - connect a web button to a Qt slot
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 767 Views 1 Watching
  • 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 Offline
    M Offline
    maximus
    wrote on last edited by
    #1

    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
    0
    • M Offline
      M Offline
      maximus
      wrote on last edited by
      #2

      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
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved