【问题标题】:Document Completed Signal inside qt using QAxWidget使用 QAxWidget 在 qt 中记录已完成的信号
【发布时间】:2017-12-27 07:14:54
【问题描述】:

我在 /examples/activeqt/webbrowser 中使用 qt 内置示例,并且我正在尝试使用 DocumentComplete SIGNAL。 我的目的是在 QAxWidget 中使用嵌入式 Internet Explorer,并在 DocumentComplete 之后弹出一条消息(带有来自网站的内容)。 NavigateComplete 信号对我来说不够好用...

代码可以在这里看到:qt Web browser Example

class MainWindow : public QMainWindow, public Ui::MainWindow
{
    Q_OBJECT
public:
    MainWindow();

public slots:
    void on_WebBrowser_TitleChange(const QString &title);
    void on_WebBrowser_ProgressChange(int a, int b);
    void on_WebBrowser_CommandStateChange(int cmd, bool on);
    void on_WebBrowser_BeforeNavigate();
    void on_WebBrowser_NavigateComplete(const QString &address);
    void on_WebBrowser_DocumentComplete(IDispatch*,QVariant&)

    void on_actionGo_triggered();
    void on_actionNewWindow_triggered();
    void on_actionAddBookmark_triggered();
    void on_actionAbout_triggered();
    void on_actionAboutQt_triggered();
    void on_actionFileClose_triggered();

private:
    QProgressBar *m_progressBar;
 
};

MainWindow::MainWindow()
{
    setupUi(this);
  
    connect(m_addressEdit, SIGNAL(returnPressed()), actionGo, SLOT(trigger()));

    connect(actionBack, SIGNAL(triggered()), WebBrowser, SLOT(GoBack()));
    connect(actionForward, SIGNAL(triggered()), WebBrowser, SLOT(GoForward()));
    connect(actionStop, SIGNAL(triggered()), WebBrowser, SLOT(Stop()));
    connect(actionRefresh, SIGNAL(triggered()), WebBrowser, SLOT(Refresh()));
    connect(actionHome, SIGNAL(triggered()), WebBrowser, SLOT(GoHome()));
    connect(actionSearch, SIGNAL(triggered()), WebBrowser, SLOT(GoSearch()));
    connect(WebBrowser,SIGNAL(DocumentComplete(IDispatch*,QVariant&), this, SLOT(on_WebBrowser_DocumentComplete(IDispatch*,QVariant&)))
}
void MainWindow::on_WebBrowser_DocumentComplete(IDispatch*,QVariant&)
{
    QMessangeBox x;
    x.setText("pop-up");
    x.exec();
}

配音员说:没有这样的插槽 MainWindow::on_WebBrowser_DocumentComplete(IDispatch*,QVaria‌​nt&)

【问题讨论】:

  • 未询问信号问题。问题是什么时候有一个“?”在那里签字。好的。你在尝试。还有什么?
  • 我的问题是如何做到这一点? iv 尝试在插槽中添加它: void on_WebBrowser_DocumentComplete(const QString &address);在很多方面(其他参数,完成而不是完成)但它不起作用
  • 提供从信号到该插槽的“连接”语句并在此处发布。确保它确实连接(符合然后观察调试器所说的内容)。
  • iv 取得了一些进展:将 DocumentComplete() 更改为 DocumentComplete(IDispatch*,QVariant&) 但现在调试器说;没有这样的插槽 MainWindow::on_WebBrowser_DocumentComplete(IDispatch*,QVariant&)
  • 需要声明和实现的代码用connect来查看。

标签: c++ qt qt5 internet-explorer-11 qaxwidget


【解决方案1】:

只要解决方法需要的不仅仅是评论:

MyWidgetUsesActiveX::MyWidgetUsesActiveX()
{
    ///
    connect(m_pActiveX, SIGNAL(signal(const QString&, int, void*)),
        this, SLOT(activexEventHandler(const QString&, int, void*)));
}

void MyWidgetUsesActiveX::activexEventHandler(
                             const QString &name, int argc, void *argv)
{
    VARIANTARG *params = (VARIANTARG*)argv;

    // See what events fired
    qDebug() << "Event:" << name << "argc:" << argc;

    // some concrete example
    if (name == "OnRemoteWindowDisplayed")
    {
        // Extract parameters
        _variant_t varValue = params[argc-1];
        bool bDisplayed = (bool)varValue;

        // hwnd
        varValue = params[argc-2];
        int iResult = (int)varValue;

        varValue = params[argc-3];
        int windowAttribute = (int) varValue;

        // CALL that stubborn slot we cannot have called otherwise
        onRemoteWindowDisplayed(bDisplayed, iResult, windowAttribute);
    }
    else if (name == "OnSomethingElse")
    {
        // extract concrete parameters and call the handler from here
        // onSomethingElse(param1, param2, param3);
    }
    else
    {
        // Log it?
    }
}

【讨论】:

    【解决方案2】:

    我通过重新生成 .moc 文件解决了这个问题。在构建配置下,qmake 的文件夹位置错误。通过将其更正到项目位置解决了我的问题。现在可以识别该插槽。谢谢大家的帮助。

    Qt Build Configuration

    【讨论】:

      猜你喜欢
      • 2014-09-05
      • 2018-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多