Hi,
I am trying to extract all items of my table and stream to txt file.
This is what I have done
Qt Code:
  1. QFile file("/home/ramraj/Desktop/bill.txt");
  2. if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
  3. qDebug()<<"file not open";
  4.  
  5. QTextStream out(&file);
  6. QString companyName=ui->companyName->text();
  7. QString companyAddress=ui->addressLabel_2->text();
  8. QString companyPhone=ui->phoneLabel_2->text();
  9. QString companyEmail=ui->emailLabel_2->text();
  10. QString companyVAT=ui->vatLabel_2->text();
  11.  
  12. out <<" "<<companyName<<endl;
  13. out <<" "<<companyAddress<<endl;
  14. out <<" "<<companyPhone<<","<<companyEmail<<endl;
  15. out <<" "<<"VAT No.:"<<companyVAT<<endl;
  16. out <<" "<<"ABBREVIATED TAX INVOICE"<<endl;
  17. out <<endl<<endl;
  18. out <<"Bill # :"<<endl;
  19. out <<"Date :"<<ui->currentDate->text()<<endl;
  20. out<<"Payment Mode: Cash"<<endl;
  21. out <<"-----------------------------------------------------------------------------------------------------------"<<endl;
  22. out <<"ID\t" <<"Particulars\t\t\t"<<"Rate\t\t"<<"Quantity\t"<<"Amount"<<endl;
  23. out <<"-----------------------------------------------------------------------------------------------------------"<<endl;
  24. QString textData;
  25. int rows = ui->billTable->rowCount();
  26. int columns = ui->billTable->columnCount();
  27. for (int i = 0; i < rows; i++) {
  28. for (int j = 0; j < columns; j++) {
  29.  
  30. textData += ui->billTable->item(i,j)->text();
  31. textData += "\t\t";
  32. }
  33. textData += "\n";
  34.  
  35. }
  36. out<<textData<<endl;
  37. out<<"---------------------------------------------------------------------------------------------------------------"<<endl;
  38. out<<" "<<"Total:"<<ui->subTotal_2->text()<<endl;
To copy to clipboard, switch view to plain text mode 


But,I am unable to get good alignment.
Here is what I have got:
Screenshot from 2019-07-16 09-53-32.jpg
Please,could anyone solve it?