Frage

I am trying to use void QWebFrame::addToJavaScriptWindowObject(const QString & name, QObject * object). My problem is when I try and call the function in the JavaScript

TypeError: Result of expression 'screen.valueChanged' [undefined] is not a function.

TimeSliceScreen::TimeSliceScreen(QWidget* parent)
:
QWidget( parent )
{
   QVBoxLayout* layout = new QVBoxLayout( this );

   _timeSlice = new QWebView( this );
   _timeSlice->setMinimumSize( 200,200);
   QSizePolicy policy = _timeSlice->sizePolicy();
   policy.setVerticalStretch(3);
   _timeSlice->setSizePolicy(policy);
   _timeSlice->settings()->setAttribute( QWebSettings::JavascriptEnabled, true );
   _timeSlice->settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled, true );
   layout->addWidget( _timeSlice );
   layout->addStretch();
   layout->addSpacing( 20 );
   _timeSlice->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);

   interface = new WebPageInterface();

   connect( _timeSlice->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), 
           this, SLOT(populateJavaScriptWindowObject()) );

}
void TimeSliceScreen::populateJavaScriptWindowObject(){
   _timeSlice->page()->mainFrame()->addToJavaScriptWindowObject(QString("screen"), 
                                                                 interface);
}

WebPageInterface is a very simple class that extends QObject and has one slot called valueChanged that is the function I am trying to call.

My JavaScript is:

function call() {
    screen.valueChanged();
}

which gets called from

<input type="hidden" id="maxhid" name="maxhid" value="{maxSlider}" onchange="call()"/>

Everything I have read says that this is the way to do it, but it's not working for me.

Keine korrekte Lösung

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top