Et avec #include <QThread> ?
Version imprimable
Et avec #include <QThread> ?
Merci beaucoup ça compile par contre quand je le lance :
:(Code:Le programme s'est terminé subitement.
utilise un débogueur ou debug le à la main car avec une telle erreur au runtime, c'est pas facile d'en déduire la cause du problème
C'est bon j'ai réussi, un énorme merci !
Pour afficher que la fin j'ai fais ceci :
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13 QString tempPath = "temp/tmp3.txt"; QFile tempToRead(tempPath); tempToRead.open(QIODevice::ReadOnly); QByteArray tempData; QStringList strList; int index; tempData += tempToRead.readAll(); if( (index = tempData.lastIndexOf( '\n' )) >= 0 ) { _mainWindow->ui->plainTextEdit->appendPlainText( tempData.left( index ) ); tempData = tempData.mid( index + 1 ); }
Merci à vous tous !
Pour ceux que ça intéresse, c'est aussi possible avec un QSocketNotifier :
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 struct Logger : QPlainTextEdit { Q_OBJECT; public: Logger () : logFile( "temp/tmp3.txt" ) { logFile.open( QIODevice::ReadOnly ); on_readyRead( logFile.handle() ); QSocketNotifier * notifier = new QSocketNotifier( logFile.handle(), QSocketNotifier::Read, this ); connect( notifier, SIGNAL(activated(int)), SLOT(on_readyRead(int)) ); } public slots: void on_readyRead( int ) { int index; buffer += logFile.readAll(); if( (index = buffer.lastIndexOf( '\n' )) >= 0 ) { appendPlainText( buffer.left( index ) ); buffer = buffer.mid( index + 1 ); } } public: QFile logFile; QByteArray buffer; };
Merci encore pour tout, vous m'avez été d'une aide précieuse !