crossplatform.ru

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


  Ответ в WebView и обработка нажатия <input type="button" id="to_button" value="Click">
Введите ваше имя
Подтвердите код

Введите в поле код из 6 символов, отображенных в виде изображения. Если вы не можете прочитать код с изображения, нажмите на изображение для генерации нового кода.
 

Опции сообщения
 Включить смайлы?
Иконки сообщения
(Опционально)
                                
                                
  [ Без иконки ]
 


Последние 10 сообщений [ в обратном порядке ]
reyzor Дата 24.4.2011, 21:01
  Да, JavaScript тебе в помощь))))
seshcher Дата 24.4.2011, 8:27
  Доброго времени суток.
Есть следующий код:


#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 и не реагирует на то, что ввел пользователь?

Просмотр темы полностью (откроется в новом окне)
RSS Текстовая версия Сейчас: 28.3.2024, 22:44