crossplatform.ru

Здравствуйте, гость ( Вход | Регистрация )

 
Ответить в данную темуНачать новую тему
> WebView и обработка нажатия <input type="button" id="to_button" value="Click">
seshcher
  опции профиля:
сообщение 24.4.2011, 8:27
Сообщение #1


Новичок


Группа: Новичок
Сообщений: 2
Регистрация: 21.11.2010
Пользователь №: 2206

Спасибо сказали: 0 раз(а)




Репутация:   0  


Доброго времени суток.
Есть следующий код:


#include <QApplication>
#include "fmain.h"


int main (int argc, char* argv[])
{
    QApplication app (argc, argv);
    fmain *mm = new fmain("Test");
    mm->showMaximized();

    return app.exec();
}


fmain.h
#ifndef FMAIN_H
#define FMAIN_H
#include <QMainWindow>
#include <QWidget>
#include <QVBoxLayout>
#include <QtWebKit>
#include <QPushButton>
#include <QMessageBox>
#include <QDebug>
#include <QWebElement>
#include <QWebElementCollection>

class QMainWindows;

class fmain : public QWidget
{
    Q_OBJECT
public:
    fmain(QString caption, QWidget * parent = 0);
private slots:
    void show_msg();
private:
    QMainWindow *m;
    QWebView *webView;
    QPushButton *Button;

};

#endif // FMAIN_H


fmain.cpp
#include "fmain.h"

fmain::fmain(QString caption, QWidget * parent) : QWidget(parent)
{
    m = new QMainWindow(parent);
    setWindowTitle(caption);

    QVBoxLayout *layout = new QVBoxLayout;
    webView = new QWebView();
    Button = new QPushButton("Button");
    layout->addWidget(webView);
    layout->addWidget(Button);
    webView->setHtml("<html><head></head><body>Par1<input type=\"text\" name=\"Par1\" value=\"Test1\"><br>Par2<input type=\"text\" name=\"Par2\"><br><input type=\"button\" id=\"to_button\" value=\"Ok\"> </body></html>");
    setLayout (layout);
    connect (Button, SIGNAL(clicked()),this, SLOT(show_msg()));
}
void fmain::show_msg ()
{
    qDebug()<< webView->page()->mainFrame()->toHtml();
     QWebElementCollection collection = webView->page()->mainFrame()->documentElement().document().findAll("input[type=text]");

    foreach (QWebElement paraElement, collection)
    {
        qDebug() << "> Element value <: " << paraElement.attribute("name") << paraElement.attribute("value");
    }
    QWebElement button2 = webView->page()->mainFrame()->documentElement().document().findFirst("input[type=button]");
}


Данный код отображает html в объекте WebView.
1) Подскажите, пожалуйста, как можно сделать обработку нажатия кнопки <input type=\"button\" id=\"to_button\" value=\"Ok\">,
чтобы по ее нажатию выводилось сообщение:
QMessageBox::information(this, tr("Print"), "Message:" + Par1 (значение введенное пользователем в WebView) + Par2 (значение введенное пользователем в WebView) );
2) Почему paraElement.attribute("name") << paraElement.attribute("value"); возвращает только те значения, которые были прописаны в html и не реагирует на то, что ввел пользователь?

Перейти в начало страницы
 
Быстрая цитата+Цитировать сообщение
reyzor
  опции профиля:
сообщение 24.4.2011, 21:01
Сообщение #2


Новичок


Группа: Новичок
Сообщений: 3
Регистрация: 19.4.2011
Пользователь №: 2618

Спасибо сказали: 0 раз(а)




Репутация:   0  


Да, JavaScript тебе в помощь))))
Перейти в начало страницы
 
Быстрая цитата+Цитировать сообщение

Быстрый ответОтветить в данную темуНачать новую тему
Теги
Нет тегов для показа


1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0




RSS Текстовая версия Сейчас: 29.3.2024, 0:12