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