Qtablewidget export to table

Source: Internet
Author: User

Tag: QT

I switched to a new company, started to develop on-site business trips, and got in touch with new applications. There are many applications that need to export tables into tables and export tables into CSV files. Share it with everyone;

lass TableToExcle : public QDialog{Q_OBJECTpublic:TableToExcle(QWidget *parent = 0, Qt::WFlags flags = 0);~TableToExcle();private:Ui::TableToExcleClass ui;private slots:void addRowSlot();void delRowSlot();void exportSlot();};


Tabletoexcle: tabletoexcle (qwidget * parent, QT: wflags flags): qdialog (parent, flags) {UI. setupui (this); UI. m_ptable-> setcolumncount (4); qtablewidgetitem * Item = new qtablewidgetitem ("0"); UI. m_ptable-> sethorizontalheaderitem (0, item); item = new qtablewidgetitem ("1"); UI. m_ptable-> sethorizontalheaderitem (1, item); item = new qtablewidgetitem ("2"); UI. m_ptable-> sethorizontalheaderitem (2, item ); Item = new qtablewidgetitem ("3"); UI. m_ptable-> sethorizontalheaderitem (3, item); UI. m_ptable-> setselectionbehavior (q1_actitemview: selectrows); Connect (UI. m_paddbtn, signal (clicked (), this, slot (addrowslot (); Connect (UI. m_pdelbtn, signal (clicked (), this, slot (delrowslot (); Connect (UI. m_pexportbtn, signal (clicked (), this, slot (exportslot ();} tabletoexcle ::~ Tabletoexcle () {} void tabletoexcle: addrowslot () {UI. m_ptable-> insertrow (UI. m_ptable-> rowcount ();} void tabletoexcle: delrowslot () {int Index = UI. m_ptable-> currentrow (); If (index>-1) {UI. m_ptable-> removerow (INDEX) ;}} void tabletoexcle: exportslot () {qstring filename = qfiledialog: getsavefilename (this, TR ("save file "),"", TR ("file (*. CSV) "); If (! Filename. isempty () {qfile file (filename); bool ret = file. Open (qiodevice: truncate | qiodevice: writeonly); If (! RET) return; qtextstream stream (& file); qstring contents; qheaderview * Header = UI. m_ptable-> horizontalheader (); If (header) {for (INT I = 0; I 





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.