Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

allign texts in QTextStream



  • Hi, I did this method to log things in my app,

      void logToFile(const int msg,const double frmcpt){
        
                QFile file("Log.txt");
                if (!file.open(QIODevice::WriteOnly | QIODevice::Append)){
                     return;
                }
        
                QTextStream t(&file);
        
                switch (msg) {
                case NEW_CONN   : t << "\n\r Connexion : " << QDateTime::currentDateTime().toString(); break;
                case RECO_FAIL  : t << "\n\r Echéc Connexion : " << QDateTime::currentDateTime().toString(); break;
                
                default: break;
                }
        
                file.close();
            }
    
    

    How can i allign the dates please ?


  • Moderators



  •  QTextStream t(&file);
                t.setFieldAlignment(QTextStream::AlignLeft);
    
                int fw = 30;
    
                switch (msg) {
                case NEW_CONN   : t << qSetFieldWidth(fw)
                                    << "\n\r Connexion : "
                                    << QDateTime::currentDateTime().toString(); break;
    
                case RECO_FAIL  : t << qSetFieldWidth(fw)
                                    << "\n\r Echéc Connexion : "
                                    << QDateTime::currentDateTime().toString(); break;
    

    Thx!


Log in to reply