0

I'm Using qt Built-in Examples in /examples/activeqt/webbrowser, and i'm trying to use DocumentComplete SIGNAL. my purpose is using embedded Internet explorer inside QAxWidget and popup a message (with contetnt from the website) after DocumentComplete. NavigateComplete Signal is not good enough for me use...

the code can be seen here : 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();
}

the dubbuger says: No such slot MainWindow::on_WebBrowser_DocumentComplete(IDispatch*,QVaria‌​nt&)

Community
  • 1
  • 1
  • No signal question asked. Question is when there is a '?' sign there. Ok. You are trying. And what? – Alexander V Dec 27 '17 at 20:07
  • my question is how it can be done? iv tried adding this in slots : void on_WebBrowser_DocumentComplete(const QString &address); in many ways(other arguments, completed instead complete) but it's not working – Mark Ruffon Dec 28 '17 at 06:02
  • Provide 'connect' statement from the signal to that slot and post it here. Make sure it really connects (complies and then watch what debugger says). – Alexander V Dec 28 '17 at 06:04
  • iv had some progress : changing DocumentComplete() to DocumentComplete(IDispatch*,QVariant&) but now the debbuger says; No such slot MainWindow::on_WebBrowser_DocumentComplete(IDispatch*,QVariant&) – Mark Ruffon Dec 28 '17 at 07:01
  • Need the code of both declaration and implementation with connect to see. – Alexander V Dec 28 '17 at 07:38
  • code added inside post above – Mark Ruffon Dec 28 '17 at 07:56
  • @AlexanderVX There is no connect. It uses Qt UI's autowire feature: `on_{objectName}_{signalName}({Parameters})` slots are automatically connected in the generated `setupUi()` code – king_nak Dec 28 '17 at 08:15
  • Try enumerating all the methods in the `WebBrowser` object, as in the code in http://doc.qt.io/qt-5/qmetaobject.html#methodCount Maybe you get a hint what's wrong – king_nak Dec 28 '17 at 08:27
  • @MarkRuffon I guess that is an old bug with Qt ActiveX event handling described here: https://forum.qt.io/topic/35085/handle-activex-events-with-custom-enum-parameters/3 Look for `connect(session, SIGNAL(signal(QString &name, int argc, void *argv)), this, SLOT(eventHandler(QString &name, int argc, void *argv)));` and try to write own slot for that. I did that once and that helped me. We can basically intercept all COM object signals like that. – Alexander V Dec 28 '17 at 08:37
  • @AlexanderVX i tried your suggestion but the event not fires. its look like its familiar with DocumentComplete(IDispatch*,QVariant&) to issue is connecting to the slot.. its keep telling me:No such slot MainWindow::on_WebBrowser_DocumentComplete(IDispatch*,QVaria‌​nt&) – Mark Ruffon Dec 28 '17 at 12:03
  • @MarkRuffon you misunderstood that approach. You can not use that handler on_WebBrowser_DocumentComplete as usual due to an error in Qt. But instead you can use eventHadler for all events when you've intercepted the name for the method. – Alexander V Dec 28 '17 at 16:42

2 Answers2

0

As long as the workaround needs more than comment:

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?
    }
}
Alexander V
  • 8,351
  • 4
  • 38
  • 47
0

i solved the issue by regenerating the .moc file. under build configuration the folder location of qmake was wrong. by correcting it to project location fixed my problem. the slot is now recognized. thank all for you help.

Qt Build Configuration