How can read input from a txt and write them to another txt file?
-
I have 2 txt file. One is for reading and the other one is writing. They should be in different threads. How can i write the data i read to another file. Here is my code for reading, queue part can be skip. I dont need it
Here is my writing thread
void MyThread::writeData() { .... emit writingDone(); }
Here is the reading part
void MyThread::run() //Reading file from txt with thread1 { QFile file("C:/Users/ilknu/Documents/MyThread/deneme.txt"); if (file.open(QIODevice::ReadOnly)) { QTextStream in (&file); while (!in.atEnd()) { QString line = in.readLine(); QStringList list = line.split(QLatin1Char(' '), Qt::SkipEmptyParts); for(const QString &entry : list) { double num = entry.toDouble(); qDebug()<< "im running on worker thread " <<num; queue.enqueue(num); } // for } // while } // if file.close(); }
-
Hi,
Please, start by learning the base concepts of threading. You are trying to go too fast with very advanced topics without having solid bases to handle them.
There are several ways to achieve what you want but from the looks of it a basic file copy operation is all that you would need.
Do not over engineer stuff.
In any case, start with the beginning.
-
@suslucoder
In the other thread, you agreed (I thought) with @Christian-Ehrlicher and me not to use threads. They are advanced, and very likely not needed.Also, please do not do as you have just done and delete that thread of yours where other people have been making posts to help you. On a forum it is customary to leave a topic in existence, not to delete it. It can be useful to others, and certainly it is relevant to this new topic you have started now.
[EDIT Either I'm going mad and you did not delete it, or you have restored the other topic now, in which case thank you! Either way it's good :) ]
-
@JonB said in How can read input from a txt and write them to another txt file?:
Either I'm going mad and you did not delete it
Sorry, I restored it without any notice here :)