Example of qt4.6: textfinder (@ eclipse + linux)

Source: Internet
Author: User

Just built the development environment of QT, try hand, see http://doc.trolltech.com/4.6/uitools-textfinder.html
. However, instead of using QT creator, eclipse is used.

 

1. textfinder. UI file (modified ):

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <UI version = "4.0"> <br/> <class> textfinderclass </class> <br/> <widget class = "qwidget" name = "textfinderclass"> <br/> <property name = "Geometry"> <br/> <rect> <br/> <x> 0 </x> <br/> <Y> 0 </Y> <br/> <width> 359 </width> <br/> <peight> 185 </peight> <br/> </rect> <br/> </property> <br/> <property name = "windowtitle"> <br/> <string> textfinder </string> <br/> </property> <br/> <widget class = "qlabel" name = "label"> <br/> <property name = "Geometry"> <br/> <rect> <br/> <x> 10 </x> <br/> <Y> 20 </Y> <br/> <width> 68 </width> <br/> <peight> 18 </peight> <br/> </rect> <br/> </property> <br/> <property name = "text"> <br/> <string> keywords: </string> <br/> </property> <br/> </widget> <br/> <widget class = "qlineedit" name = "lineedit"> <br/> <property name = "Geometry"> <br/> <rect> <br/> <x> 100 </x> <br/> <Y> 20 </Y> <br/> <width> 141 </width> <br/> <peight> 26 </peight> <br/> </rect> <br/> </property> <br/> </widget> <br/> <widget class = "qtextedit" name = "textedit"> <br/> <property name = "Geometry"> <br/> <rect> <br/> <x> 20 </x> <br/> <Y> 60 </Y> <br/> <width> 321 </width> <br/> <peight> 111 </peight> <br/> </rect> <br/> </property> <br/> </widget> <br/> <widget class = "qpushbutton" name = "findbutton"> <br/> <property name = "Geometry"> <br/> <rect> <br/> <x> 250 </x> <br/> <Y> 20 </Y> <br/> <width> 92 </width> <br/> <peight> 28 </peight> <br/> </rect> <br/> </property> <br/> <property name = "text"> <br/> <string> Find </string> <br/> </property> <br/> </widget> <br/> <layoutdefault spacing = "6" margin = "11" /> <br/> <resources/> <br/> <connections/> <br/> </UI>

2. textfinder. h file (modified ):

# Ifndef textfinder_h <br/> # define textfinder_h <br/> # include <qtgui/qwidget> <br/> # include "ui_textfinder.h" <br/> class textfinder: public qwidget <br/>{< br/> q_object <br/> Public: <br/> textfinder (qwidget * parent = 0); <br/> ~ Textfinder (); <br/> PRIVATE: <br/> UI: textfinderclass UI; <br/> private slots: <br/> void on_findbutton_clicked (); <br/> PRIVATE: <br/> void loadtextfile (); <br/>}; <br/> # endif // textfinder_h

3. textfinder. cpp file (modified ):

# Include <qtcore/qfile> <br/> # include <qtcore/qtextstream> <br/> # include "textfinder. H "<br/> textfinder: textfinder (qwidget * parent) <br/>: qwidget (parent) <br/>{< br/> UI. setupui (this); <br/> loadtextfile (); <br/>}< br/> textfinder ::~ Textfinder () <br/>{< br/>}< br/> void textfinder: loadtextfile () <br/>{< br/> qfile inputfile ("input.txt"); <br/> inputfile. open (qiodevice: readonly); <br/> qtextstream in (& inputfile); <br/> qstring line = in. readall (); <br/> inputfile. close (); <br/> UI. textedit-> setplaintext (line); <br/> qtextcursor cursor = UI. textedit-> textcursor (); <br/> cursor. moveposition (qtextcursor: Start, qtextcursor: moveanchor, 1); <br/>}< br/> void textfinder: on_findbutton_clicked () <br/>{< br/> qstring searchstring = UI. lineedit-> text (); <br/> UI. textedit-> Find (searchstring, qtextdocument: findwholewords); <br/>}

4. ui_textfinder.h file (View ):

/*************************************** **************************************** * <Br/> ** form generated from reading UI file 'textfinder. ui '<br/> ** created: Fri Dec 25 19:52:16 2009 <br/> **: qt User Interface compiler version 4.6.0 <br/> ** warning! All changes made in this file will be lost when recompiling UI file! <Br/> ************************************ **************************************** * ***/<br/> # ifndef ui_textfinder_h <br/> # define ui_textfinder_h <br/> # include <qtcore/qvariant> <br/> # include <qtgui/qaction> <br/> # include <qtgui/qapplication> <br/> # include <qtgui/qbuttongroup> <br/> # include <qtgui/qheaderview> <br/> # include <qtgui/qlabel> <br/> # include <qtgui/qlineedit> <br/> # include <qtgui/qpushbutton> <br/> # include <qtgui/qtextedit> <br /># include <qtgui/qwidget> <br/> qt_begin_namespace <br/> class ui_textfinderclass <br/>{< br/> public: <br/> qlabel * label; <br/> qlineedit * lineedit; <br/> qtextedit * textedit; <br/> qpushbutton * findbutton; <br/> void setupui (qwidget * textfinderclass) <br/>{< br/> If (textfinderclass-> objectname (). isempty () <br/> textfinderclass-> setobjectname (qstring: fromutf8 ("textfinderclass"); <br/> textfinderclass-> resize (359,185 ); <br/> label = new qlabel (textfinderclass); <br/> label-> setobjectname (qstring: fromutf8 ("label ")); <br/> label-> setgeometry (qrect (10, 20, 68, 18); <br/> lineedit = new qlineedit (textfinderclass ); <br/> lineedit-> setobjectname (qstring: fromutf8 ("lineedit"); <br/> lineedit-> setgeometry (qrect (100, 20,141, 26 )); <br/> textedit = new qtextedit (textfinderclass); <br/> textedit-> setobjectname (qstring: fromutf8 ("textedit ")); <br/> textedit-> setgeometry (qrect (20, 60,321,111); <br/> findbutton = new qpushbutton (textfinderclass); <br/> findbutton-> setobjectname (qstring:: fromutf8 ("findbutton"); <br/> findbutton-> setgeometry (qrect (250, 20, 92, 28); <br/> retranslateui (textfinderclass ); <br/> qmetaobject: connectslotsbyname (textfinderclass); <br/>}// setupui <br/> void retranslateui (qwidget * textfinderclass) <br/>{< br/> textfinderclass-> setwindowtitle (qapplication: translate ("textfinderclass", "textfinder", 0, qapplication: unicodeutf8 )); <br/> label-> settext (qapplication: translate ("textfinderclass", "keywords:", 0, qapplication: unicodeutf8 )); <br/> findbutton-> settext (qapplication: translate ("textfinderclass", "find", 0, qapplication: unicodeutf8 )); <br/>}// retranslateui <br/>}; <br/> namespace UI {<br/> class textfinderclass: Public ui_textfinderclass {}; <br/>}// namespace UI <br/> qt_end_namespace <br/> # endif // ui_textfinder_h

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.