user2729325
user2729325

Reputation: 23

Qt Bind slot and signal failed QMainWindow QWebview

.h file:

#include <QMainWindow>
#include <QWidget>
#include <QTimer>
#include "tool/shape.h"
#include "tool/sensor.h"
#include "tool/sensor_set.h"
#include "tool/track_unit.h"
#include "tool/track.h"
#include "tool/track_set.h"
#include "tool/opera.h"

class QWebView;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
protected Q_SLOTS:
    void test();
    //void startOpera();

public:
Q_SIGNALS:
    void updateObject(const QString& data);

private:
    //Ui::MainWindow *ui;
    QWebView* m_webView;
tools::Opera2D* opera;
tools::Opera2D::Iterator *iter;
tools::Opera2D::OperaState* opera_state;

QTimer* m_timerOpera;

};

.cpp

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
//ui(new Ui::MainWindow)*/
{
    m_webView = new QWebView(this);
    QUrl url = QUrl("file:///F:/WORKSTATON/SVN/txm/txm/google/index.html");
    m_webView->load(url);
    setCentralWidget(m_webView);
    move(QPoint(200, 200));
    QObject::connect(this, SIGNAL(updateObject(const QString&)),
           m_webView->page()->mainFrame(), SLOT(evaluateJavaScript(const QString&)));
}

mingw g++ show:

error:

F:\WORKSTATON\SVN\tools_temp\mainwindow.cpp:162: error: no matching function for call to 'MainWindow::connect(MainWindow* const, const char*, QWebFrame*, const char*)'
                m_webView->page()->mainFrame(), SLOT(evaluateJavaScript(const QString&)));

error:

D:\Program\Qt\Qt5.3.1\5.3\mingw482_32\include\QtCore\qobject.h:215: error: no type named 'Object' in 'struct QtPrivate::FunctionPointer<const char*>'

Upvotes: 2

Views: 202

Answers (1)

L&#225;szl&#243; Papp
L&#225;szl&#243; Papp

Reputation: 53175

Given that you have the following checkboxes ticked:

  • Q_OBJECT macro not missing
  • signals well marked
  • slots well marked
  • argument numbers are matching
  • argument types are matching
  • You do not have a typo
  • You are inheriting QObject
  • You are using pointers for the sender and receiver
  • You run qmake for the latest state
  • etc

The reason is that you forgot to include the header file for the returned heap object, namely:

#include <QWebFrame>

For future reference: given that you use Qt 5.3.1, you could try using this form should you have Qt 5 available on other supported platforms, too, or conditionally at least:

connect(this, &MainWindow::updateObject,
        m_webView->page()->mainFrame(), &QWebFrame::evaluateJavaScript);

Having said that, you have other minor issues with your code, but they are only tangentially related:

  • signals in your scenario do not make much sense as being marked public in the header.

  • It is unusual for the receiver to be this object; in other words, you may reconsider your design why not just calling the slot directly where you would emit or connect from this receiver in other place of your codebase.

Upvotes: 1

Related Questions