[Development] ActiveQt Events

neel patel neel5481 at gmail.com
Wed Jun 28 11:23:36 CEST 2017


Hi,

I tried the steps provided by you and it is working nicely.. Thank you
Henry for your support.


Couple of queries regarding same:-

1)

As I have QTabWidget and i am opening another URL in new window with custom
Back/Forward button.  When user navigate to URL and again come back then we
are using below code for Back and Forward button click signal.

m_activeX->dynamicCall("GoBack()");
m_activeX->dynamicCall("GoForward()");

Above will work fine but how can we know wether we can go back or not and
depending on that enable/disable Back/Forward buttons. As of now when we
come to first page and call "GoBack" then it gives exception. I want to
know before click on buttons. Is there anyway ?


2)

I am using "window.load" at JS side and we are getting "NewWindow3" signal
which is fine but after that below code fails which gives script error on
Qt side saying "Unable to get property addEventListener of undefined or
null reference. Do you want to continue execute script ?"

window.addEventListener("load", function() { }  --

Should we change IE browser version used in QAxWidget to resolve this issue
Or any other work around to stop giving this message ?

Thanks in Advance.



On Tue, Jun 27, 2017 at 5:47 PM, neel patel <neel5481 at gmail.com> wrote:

> Thank you Henry. I will check and keep you updated.
>
>
> On Tue, Jun 27, 2017 at 5:26 PM, Henry Skoglund <fromqt at tungware.se>
> wrote:
>
>> On 2017-06-27 10:54, neel patel wrote:
>>
>>> Hi All,
>>>
>>> As I am using "QAxWidget". I took the "webbrowser" example as reference.
>>> As I am using "QTabWidget" as mainwindow widget and adding "QAxWidget"
>>> as tab widget. Below is the code for reference.
>>>
>>>
>>>      m_tabWidget = new QTabWidget(mainwindow);
>>>
>>>      m_mainGridLayout = new QGridLayout(m_tabWidget);
>>>      m_mainGridLayout->setContentsMargins(0, 0, 0, 0);
>>>
>>>      m_MainTab = new QWidget(m_tabWidget);
>>>      m_tabGridLayout = new QGridLayout(m_MainTab);
>>>      m_tabGridLayout->setContentsMargins(0, 0, 0, 0);
>>>
>>>      m_activeX = new WebAxWidget(m_MainTab);
>>>      m_activeX->setControl(QStringLiteral("{8856F961-340A-11D0-A
>>> 96B-00C04FD705A2}"));
>>>      m_activeX->setObjectName(QStringLiteral("WebBrowser"));
>>>      m_activeX->setFocusPolicy(Qt::StrongFocus);
>>>
>>>      m_tabGridLayout->addWidget(m_activeX, 0, 0, 1, 1);
>>>      m_tabWidget->addTab(m_MainTab, QString());
>>>
>>>      mainwindow->setCentralWidget(m_tabWidget);
>>>
>>> class WebAxWidget : public QAxWidget
>>> {
>>> public:
>>>
>>>      WebAxWidget(QWidget* parent = 0, Qt::WindowFlags f = 0)
>>>          : QAxWidget(parent, f)
>>>      {
>>>      }
>>> }
>>>
>>>
>>>
>>> I want to receive events like NewWindow3, NewWindow2, BeforeNavigate2
>>> with Qt. As such there is no signal available in "QAxWidget". How can we
>>> receive those signals from windows COM interface ?
>>>
>>> Let me know reference or pointers so that i can implement and suggest in
>>> above code.
>>>
>>> Thanks in Advance.
>>>
>>
>> Hi, you can receive those events through the generic QAxBase::signal, see
>> http://doc.qt.io/qt-5/qaxbase.html#signal
>> In it, you'll see the example code for receiving "BeforeNavigate2", and
>> all the other event flavors you retrieve the same way.
>>
>> So first, add the slot declaration to your MainWindow class:
>> ...
>> private slots:
>>     void slot(const QString& name,int argc, void* argv);
>> ...
>>
>> then connect your m_activeX object to that signal, here is some sample
>> code added after your " mainwindow->setCentralWidget(m_tabWidget);":
>>
>> ...
>>     connect(m_activeX,SIGNAL(signal(const QString&,int,void*)),this,SLOT(slot(const
>> QString&,int,void*)));
>> //    connect(m_activeX,&QAxWidget::signal,this,&MainWindow::slot);  //
>> this is better syntax but alas will *not* compile :-(
>>
>> // setup a sample navigation
>>     QString url = "http://doc.qt.io/qt-5/qaxbase.html";
>>     m_activeX->dynamicCall("Navigate(const QString&)",url);
>> }
>>
>> // here's how to receive all of them
>> // you'll have to check the name for the correct one, I'll give you 2 for
>> free
>> // just add the others you need...
>> // note: the example in QAxBase::signal is too old to compile correctly,
>> (changed below)
>>
>> // need this for the VARIANTARG chaps
>> #include "windows.h"
>>
>> void MainWindow::slot(const QString &name, int argc, void *argv)
>> {
>>     VARIANTARG *params = (VARIANTARG*)argv;
>>     if (name.startsWith("BeforeNavigate2("))
>>     {
>>     // "BeforeNavigate2(IDispatch*,QVariant&,QVariant&,QVariant&,QV
>> ariant&,QVariant&,bool&)"
>>         IDispatch *pDisp = params[argc-1].pdispVal;
>>         VARIANTARG URL = *params[argc-2].pvarVal;
>>         VARIANTARG Flags = *params[argc-3].pvarVal;
>>         VARIANTARG TargetFrameName = *params[argc-4].pvarVal;
>>         VARIANTARG PostData = *params[argc-5].pvarVal;
>>         VARIANTARG Headers = *params[argc-6].pvarVal;
>>         VARIANT_BOOL *Cancel = params[argc-7].pboolVal;
>>
>>         QString url = QString::fromStdWString(URL.bstrVal);
>>         qDebug() << "BeforeNavigate2, ur" << url;
>>     }
>>
>>     if (name.startsWith("NewWindow3("))
>>     {
>>     // NewWindow3(IDispatch**,bool&,uint,QString,QString)"
>>         IDispatch *pDisp = params[argc-1].pdispVal;
>>         VARIANT_BOOL* Cancel = params[argc-2].pboolVal;
>>         uint Flags = params[argc-3].uintVal;
>>         BSTR URLContext = params[argc-4].bstrVal;
>>         BSTR URL = params[argc-5].bstrVal;
>>
>>         QString urlContext = QString::fromStdWString(URLContext);
>>         QString url = QString::fromStdWString(URL);
>>         qDebug() << "NewWindow3, opening" << url << "from" << urlContext;
>>     }
>> }
>> ...
>>
>> Good luck! Rgrds Henry
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20170628/b0ea3817/attachment.html>


More information about the Development mailing list