[QT] Example Analysis of QT tutorial [10] File Attribute Viewer (qfileinfo)

Source: Internet
Author: User

The key knowledge is nearly commented out in the code...
Please read the code carefully
Original article
Reprinted please keep this link

Http://blog.csdn.net/siren0203

 

Header file

Getinfo. h

 

# Ifndef header_h <br/> # define header_h <br/> # include <qdialog> <br/> # include <qobject> <br/> class qpushbutton; <br/> class qlineedit; <br/> class qpushbutton; <br/> class qlabel; <br/> class qvboxlayout; <br/> class qhboxlayout; <br/> class qgridlayout; <br/> class getfileinfo: Public qdialog {<br/> q_object <br/> Public: <br/> getfileinfo (); <br/> Public: <br/> qpushbutton * openfile; <br/> qpushbutton * getinfo; <br/> qlineedit * filename; <br/> qlineedit * editsize; <br/> qlineedit * editcreatetime; <br/> qlineedit * editupdatetime; <br/> qlineedit * editlastvtime; <br/> qlabel * labelfilename; <br/> qlabel * labelsize; <br/> qlabel * labelcreatetime; <br/> qlabel * labelupdatetime; <br/> qlabel * labellastvtime; <br/> qvboxlayout * vbox; <br/> qhboxlayout * hbox; <br/> qgridlayout * gbox; <br/> Public slots: <br/> void openfiledlg (); <br/> void getfiledlg (); </P> <p >}; <br/> # endif // header_h <br/>

 

 

Program Implementation Code

 

Main. cpp

 

# Include <qapplication> <br/> # include <qfiledialog> <br/> # include <qpushbutton> <br/> # include <qlineedit> <br/> # include <qlabel> <br/> # include <qvboxlayout> <br/> # include <qhboxlayout> <br/> # include <qgridlayout> <br/> # include <qtextcodec> <br/> # include <qdialog> <br/> # include <qfileinfo> <br/> # include <qdatetime> <br/> # include "getinfo. H "<br/> getfileinfo: getfileinfo () {<br/> openfile = new qpushbutton (TR (" open ")); <br/> getinfo = new qpushbutton (TR ("get info"); <br/> editsize = new qlineedit (this ); <br/> editcreatetime = new qlineedit (this); <br/> editupdatetime = new qlineedit (this); <br/> editlastvtime = new qlineedit (this ); <br/> filename = new qlineedit (this); <br/> labelfilename = new qlabel (TR ("file name ")); <br/> labelsize = new qlabel (TR ("file size"); <br/> labelcreatetime = new qlabel (TR ("Creation Time ")); <br/> labelupdatetime = new qlabel (TR ("modification time"); <br/> labellastvtime = new qlabel (TR ("last access time ")); <br/> gbox = new qgridlayout (this); <br/> gbox-> addwidget (labelfilename, 0, 1); <br/> gbox-> addwidget (filename, 0, 2 ); <br/> gbox-> addwidget (openfile,); <br/> gbox-> addwidget (labelsize,); <br/> gbox-> addwidget (editsize, 1, 2); <br/> gbox-> addwidget (labelcreatetime, 2, 1); <br/> gbox-> addwidget (editcreatetime, 2, 2 ); <br/> gbox-> addwidget (labelupdatetime, 3,1); <br/> gbox-> addwidget (editupdatetime, 3,2); <br/> gbox-> addwidget (labellastvtime, 4, 1); <br/> gbox-> addwidget (editlastvtime, 4, 2); </P> <p> hbox = new qhboxlayout (this ); <br/> hbox-> addwidget (getinfo); <br/> gbox-> addlayout (hbox, 5, 2); <br/> setlayout (gbox ); <br/> // associate the signal to the slot .. <br/> connect (openfile, signal (clicked (), this, slot (openfiledlg (); <br/> connect (getinfo, signal (clicked ()), this, slot (getfiledlg (); <br/> setwindowtitle (TR ("person http://blog.csdn.net/siren0203 ")); <br/>}< br/> // open the file <br/> void getfileinfo: openfiledlg () {<br/> qstring files = qfiledialog: getopenfilename (this ); <br/> filename-> settext (files); <br/>}< br/> // obtain File Information <br/> void getfileinfo: getfiledlg () {<br/> // open the file <br/> qfileinfo F (filename-> text ()); <br/> // obtain the file creation time <br/> qdatetime createtime = f. created (); <br/> // obtain the last file update time <br/> qdatetime updatetime = f. lastmodified (); <br/> // obtain the last file browsing time <br/> qdatetime lastrtime = f. lastread (); <br/> // display attributes <br/> editsize-> settext (qstring ("% 1 "). arg (F. size (); <br/> editcreatetime-> settext (createtime. tostring (); <br/> editupdatetime-> settext (updatetime. tostring (); <br/> editlastvtime-> settext (lastrtime. tostring (); <br/>}< br/> int main (INT argc, char ** argv) {<br/> qapplication app (argc, argv ); <br/> qtextcodec: setcodecfortr (qtextcodec: codecforname ("gb2312"); <br/> getfileinfo Info; <br/> info. show (); <br/> return app.exe C (); <br/>}

 

 

 

 

 

 

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.