我试图处理大块csv数据,因为它在块。如果我在没有线程的情况下运行chunkprocess,应用程序不会崩溃。但是,一旦我添加到线程池中,应用程序就会崩溃并引发以下错误。 ChunkProcess运行只发出(没有别的)信号shared_ptr,它是ChunkProcess的私有成员。在网上阅读文章后,我发现shared_ptr不是线程安全的,除非您复制它...所以有什么办法可以在使用它作为信号时复制它?Qt shared_ptr信号与QThreadPool
ASSERT: "!d->ref.isShared()" in file tools\qlist.cpp, line 162
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
QObject::~QObject: Timers cannot be stopped from another thread
void MainWindow::parseCSV(QString file_name)
{
QFile file(file_name);
if (!file.open(QIODevice::ReadOnly))
return;
QThreadPool *threadPool = QThreadPool::globalInstance();
QList<QList<QByteArray>>* data = new QList<QList<QByteArray>>;
int count = 0;
while (!file.atEnd()) {
++count;
QByteArray line = file.readLine();
data->append(line.split(','));
if (count > 10000) {
ChunkProcessor* chunkprocess = new ChunkProcessor(data);
connect(chunkprocess,
SIGNAL(finished(std::shared_ptr<customClass::ProcessedData>)),
this,
SLOT(readingFinished(std::shared_ptr<customClass::ProcessedData>)));
// threadPool->start(chunkprocess);
// threadPool->waitForDone();
chunkprocess->run();
delete data;
data = new QList<QList<QByteArray>>;
count = 0;
}
}
delete data;
}
void MainWindow::readingFinished(std::shared_ptr<customClass::ProcessedData> data)
{
emittedData.append(data);
qInfo()<<"got to finish reading";
}
为什么你要在堆上分配一个QList?在堆栈上创建它! – 2017-08-30 20:52:22
谢谢你的建议,一旦我找出线程过程,我一定会改变它。 – ntmt