<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/examples/network/archivesearch/archivesearch.doc:5 --> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>A qt-interest mail archive search</title> <style type="text/css"><!-- fn { margin-left: 1cm; text-indent: -1cm; } a:link { color: #004faf; text-decoration: none } a:visited { color: #672967; text-decoration: none } body { background: #ffffff; color: black; } --></style> </head> <body> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr bgcolor="#E5E5E5"> <td valign=center> <a href="index.html"> <font color="#004faf">Home</font></a> | <a href="classes.html"> <font color="#004faf">All Classes</font></a> | <a href="mainclasses.html"> <font color="#004faf">Main Classes</font></a> | <a href="annotated.html"> <font color="#004faf">Annotated</font></a> | <a href="groups.html"> <font color="#004faf">Grouped Classes</font></a> | <a href="functions.html"> <font color="#004faf">Functions</font></a> </td> <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>A qt-interest mail archive search</h1> <p> <p> This example does a search on the qt-interest mailinglist archives. It uses <a href="qhttp.html">TQHttp</a> to issue the search command and to fetch the results. The GUI parts were done using <a href="designer-manual.html">TQt Designer</a>. <p> <hr> <p> The implementation of the HTTP requests (archivedialog.ui.h): <p> <pre>/**************************************************************************** ** $Id: qt/archivedialog.ui.h 3.3.8 edited Jan 29 15:54 $ ** ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved. ** ** This file is part of an example program for TQt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ /**************************************************************************** ** ui.h extension file, included from the uic-generated form implementation. ** ** If you wish to add, delete or rename functions or slots use ** TQt Designer which will update this file, preserving your code. Create an ** init() function in place of a constructor, and a destroy() function in ** place of a destructor. *****************************************************************************/ void ArchiveDialog::init() { connect(&articleSearcher, SIGNAL(done(bool)), this, SLOT(searchDone(bool))); connect(&articleFetcher, SIGNAL(done(bool)), this, SLOT(fetchDone(bool))); connect(myListView, SIGNAL(selectionChanged(TQListViewItem*)), this, SLOT(fetch(TQListViewItem*))); connect(myLineEdit, SIGNAL(returnPressed()), this, SLOT(search())); connect(myListView, SIGNAL(returnPressed(TQListViewItem*)), this, SLOT(fetch(TQListViewItem*))); connect(myPushButton, SIGNAL(clicked()), this, SLOT(close())); } void ArchiveDialog::fetch( <a href="qlistviewitem.html">TQListViewItem</a> *it ) { <a name="x477"></a> <a href="qurl.html">TQUrl</a> u(it-><a href="qlistviewitem.html#text">text</a>(1)); <a name="x485"></a> articleFetcher.setHost(u.<a href="qurl.html#host">host</a>()); articleFetcher.get(it-><a href="qlistviewitem.html#text">text</a>(1)); } void ArchiveDialog::fetchDone( bool error ) { if (error) { <a name="x478"></a> TQMessageBox::<a href="qmessagebox.html#critical">critical</a>(this, "Error fetching", "An error occurred when fetching this document: " + articleFetcher.errorString(), TQMessageBox::Ok, TQMessageBox::NoButton); } else { myTextBrowser->setText(articleFetcher.readAll()); } } void ArchiveDialog::search() { if (articleSearcher.state() == TQHttp::HostLookup || articleSearcher.state() == TQHttp::Connecting || articleSearcher.state() == TQHttp::Sending || articleSearcher.state() == TQHttp::Reading) { articleSearcher.abort(); } if (myLineEdit->text() == "") { TQMessageBox::<a href="qmessagebox.html#critical">critical</a>(this, "Empty query", "Please type a search string.", TQMessageBox::Ok, TQMessageBox::NoButton); } else { <a name="x474"></a> TQApplication::<a href="qapplication.html#setOverrideCursor">setOverrideCursor</a>(TQCursor(TQt::WaitCursor)); articleSearcher.setHost("lists.trolltech.com"); <a href="qhttprequestheader.html">TQHttpRequestHeader</a> header("POST", "/qt-interest/search.php"); <a name="x476"></a> header.<a href="qhttpheader.html#setValue">setValue</a>("Host", "lists.trolltech.com"); <a name="x475"></a> header.<a href="qhttpheader.html#setContentType">setContentType</a>("application/x-www-form-urlencoded"); <a href="qstring.html">TQString</a> encodedTopic = myLineEdit->text(); <a name="x484"></a> TQUrl::<a href="qurl.html#encode">encode</a>(encodedTopic); <a href="qstring.html">TQString</a> searchString = "qt-interest=on&search=" + encodedTopic; <a name="x483"></a> articleSearcher.request(header, searchString.<a href="qstring.html#utf8">utf8</a>()); } } void ArchiveDialog::searchDone( bool error ) { if (error) { TQMessageBox::<a href="qmessagebox.html#critical">critical</a>(this, "Error searching", "An error occurred when searching: " + articleSearcher.errorString(), TQMessageBox::Ok, TQMessageBox::NoButton); } else { <a href="qstring.html">TQString</a> result(articleSearcher.readAll()); <a href="qregexp.html">TQRegExp</a> rx("<a href=\"(http://lists\\.trolltech\\.com/qt-interest/.*)\">(.*)</a>"); <a name="x482"></a> rx.<a href="qregexp.html#setMinimal">setMinimal</a>(TRUE); int pos = 0; while (pos >= 0) { <a name="x481"></a> pos = rx.<a href="qregexp.html#search">search</a>(result, pos); if (pos > -1) { <a name="x480"></a> pos += rx.<a href="qregexp.html#matchedLength">matchedLength</a>(); <a name="x479"></a> new <a href="qlistviewitem.html">TQListViewItem</a>(myListView, rx.<a href="qregexp.html#cap">cap</a>(2), rx.<a href="qregexp.html#cap">cap</a>(1)); } } } <a name="x473"></a> TQApplication::<a href="qapplication.html#restoreOverrideCursor">restoreOverrideCursor</a>(); } </pre> <p> <hr> <p> Main (main.cpp): <p> <pre>/**************************************************************************** ** $Id: qt/main.cpp 3.3.8 edited Jan 11 14:37 $ ** ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved. ** ** This file is part of an example program for TQt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ #include "archivedialog.h" #include <<a href="qapplication-h.html">qapplication.h</a>> int main(int argc, char **argv) { <a href="qapplication.html">TQApplication</a> a( argc, argv ); ArchiveDialog ad; ad.show(); <a name="x489"></a><a name="x487"></a> TQObject::<a href="qobject.html#connect">connect</a>( &a, SIGNAL(<a href="qapplication.html#lastWindowClosed">lastWindowClosed</a>()), <a name="x488"></a> &a, SLOT(<a href="qapplication.html#quit">quit</a>()) ); <a name="x486"></a> return a.<a href="qapplication.html#exec">exec</a>(); } </pre> <p>See also <a href="network-examples.html">Network Examples</a>. <!-- eof --> <p><address><hr><div align=center> <table width=100% cellspacing=0 border=0><tr> <td>Copyright © 2007 <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a> <td align=right><div align=right>TQt 3.3.8</div> </table></div></address></body> </html>