PDA

View Full Version : Accessing QTextEdit



LordQt
1st December 2008, 11:34
Hello friends,

how can I access my QTexEdit from another class or from a Thread.



thr_startReadTrackFile = new readTrackFile(selectedFile, bodyEdit);
thr_startReadTrackFile->start();


when I append a line to the TextEdit in my Thread I have an Error .....

my Thread declaration looks like


//************************************************** ************************
class readTrackFile : public QThread
//************************************************** ************************
{
Q_OBJECT
public:
readTrackFile(const QString &p_inFile,
QTextEdit *p_bodyEditCopy,
QObject* parent = 0);
virtual ~readTrackFile() { }

public slots:
protected:
void run();
private:
QString qstr_inFile;
QTextEdit* bodyEditCopy;


and in the implemantion



void readTrackFile::run()
{
...

QFile inFile(qstr_inFile);
QString qstr_textLine;

if(inFile.exists() )
{
if (inFile.open(QFile::ReadOnly | QFile::Text) )
{
QTextStream filestream( &inFile );

...
while (!filestream.atEnd())
{
qstr_textLine = filestream.readLine();
if(qstr_textLine.count(";",Qt::CaseInsensitive)== 36)
{
bodyEditCopy->append(qstr_textLine);

...
}
else
{
...
...
...
}
}
}
}
inFile.close();
}


Could anybody see the misunderstanding from my side....

The Storm
1st December 2008, 18:20
You can not change the GUI from the Non-GUI thread, most of the time you will get crash if you do. Use signals and slots in order to update the GUI when something happens in to the thread. :)

LordQt
1st December 2008, 21:36
hmmm.... ok thx for your help my friend

cu