Namespaces
Variants
Actions
Revision as of 04:14, 11 October 2012 by hamishwillee (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Archived:Load a Selected Web Search Engine in a QWebView

Jump to: navigation, search
Archived.png
Archived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Qt Quick should be used for all UI development on mobile devices. The approach described in this article (based on QWidget) is deprecated.


Article Metadata

Tested with
Devices(s): S60 Emulator

Compatibility
Platform(s): S60 3rd Edition, FP1, FP2
S60 5th Edition

Article
Keywords: QPushButton,QWebView
Created: mind_freak (08 Jul 2009)
Last edited: hamishwillee (11 Oct 2012)

Contents

OverView

This article allows you to select a search engine from a list and enter text, then launches the search engine using a QWebView. The application is limited because after first search the native interface is no longer visible and we then need to use the search engine's web page directly.

This example makes the use of following classes:

  • QWebView - Provides a widget that is used to view and edit web documents.
  • QPushButton - Provides a command button to search.


Preconditions

  • Download and Install the Qt SDK

source code

cpp file

#include "engine.h"
#include "ui_engine.h"
 
engine::engine(QWidget *parent)
: QWidget(parent), ui(new Ui::engineClass)
{
ui.setupUi(this);
msg=new QMessageBox();
ui.comboBox.addItem("--Select--");
ui.comboBox.addItem("altavista.com");
ui.comboBox.addItem("ask.com");
ui.comboBox.addItem("google.com");
ui.comboBox.addItem("goto.com");
ui.comboBox.addItem("hotbot.com");
ui.comboBox.addItem("looksmart.com");
ui.comboBox.addItem("lycos.com");
ui.comboBox.addItem("metacrawler.com");
ui.webView.hide();
ui.Bar.setValue(0);
QObject::connect(ui.search,SIGNAL(clicked()),this,SLOT(viral()));
QObject::connect(ui.webView,SIGNAL(loadProgress(int)),ui.Bar,SLOT(setValue(int)));
 
}
 
engine::~engine()
{
delete ui;
}
void engine::viral()
{
 
if(ui.comboBox.currentText()=="--Select--")
{
msg->setText("Please select Search Engine");
msg->exec();
 
}
else if(ui.comboBox.currentText()=="altavista.com")//Search on specific website by comparing strings
{
ui.label.setText(ui.comboBox.currentText());
ui.line.hide();
ui.comboBox.hide();
ui.search.hide();
str="http://www.altavista.com/cgi-bin/query?pg=q&what=web&fmt=.&q=";
str1=ui.line.text();
str3=str+str1;
ui.webView.show();
ui.webView.load(QUrl(str3));
 
}
else if(ui.comboBox.currentText()=="ask.com")
{
ui.label.setText(ui.comboBox.currentText());
ui.line.hide();
ui.comboBox.hide();
ui.search.hide();
str="http://www.ask.com/main/askjeeves.asp?x=22&y=13&ask=";
str1=ui.line.text();
str3=str+str1;
ui.webView.show();
ui.webView.load(QUrl(str3));
}
else if(ui.comboBox.currentText()=="google.com")
{
ui.label.setText(ui.comboBox.currentText());
ui.line.hide();
ui.comboBox.hide();
ui.search.hide();
str="http://www.google.com/search?btnG=Google+Search&q=";
str1=ui.line.text();
str3=str+str1;
ui.webView.show();
ui.webView.load(QUrl(str3));
}
else if (ui.comboBox.currentText()=="goto.com")
{
ui.label.setText(ui.comboBox.currentText());
ui.line.hide();
ui.comboBox.hide();
ui.search.hide();
str="http://www.goto.com/d/search/?type=home&tm=1&Keywords=";
str1=ui.line.text();
str3=str+str1;
ui.webView.show();
ui.webView.load(QUrl(str3));
}
else if(ui.comboBox.currentText()=="hotbot.com")
{
ui.label.setText(ui.comboBox.currentText());
ui.line.hide();
ui.comboBox.hide();
ui.search.hide();
str="http://www.hotbot.com/search.html?SM=MC&_v=1.0&MT=";
str1=ui.line.text();
str3=str+str1;
ui.webView.show();
ui.webView.load(QUrl(str3));
}
 
else if(ui.comboBox.currentText()=="looksmart.com")
{
ui.label.setText(ui.comboBox.currentText());
ui.line.hide();
ui.comboBox.hide();
ui.search.hide();
str="http://www.looksmart.com/r_search?look=&key=";
str1=ui.line.text();
str3=str+str1;
ui.webView.show();
ui.webView.load(QUrl(str3));
}
else if(ui.comboBox.currentText()=="lycos.com")
{
ui.label.setText(ui.comboBox.currentText());
ui.line.hide();
ui.comboBox.hide();
ui.search.hide();
str="http://www.lycos.com/cgi-bin/pursuit?query=";
str1=ui.line.text();
str3=str+str1;
ui.webView->show();
ui->webView->load(QUrl(str3));
}
else if(ui->comboBox->currentText()=="metacrawler.com")
{
ui->label->setText(ui->comboBox->currentText());
ui->line->hide();
ui->comboBox->hide();
ui->search->hide();
str="http://www.metacrawler.com/cgi-bin/nph-metaquery.p?general=";
str1=ui.line.text();
str3=str+str1;
ui.webView.show();
ui.webView.load(QUrl(str3));
}
else
{
 
exit(1);
}
 
 
}

Screenshot

Searchme.JPG

Searchme1.JPG

602 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved