大容量のcsvデータをチャンクに変換して処理しようとしています。スレッド処理なしでchunkprocessを実行すると、アプリケーションはクラッシュしません。ただし、スレッドプールに追加するとすぐに、アプリケーションがクラッシュし、次のエラーがスローされます。 ChunkProcessは、ChunkProcessのプライベートメンバーであるshared_ptrを送信します(それ以外は何も送信しません)。記事をオンラインで読むと、shared_ptrはスレッドのコピーを作成しない限りスレッドセーフではないことがわかりました。それで、シグナルとして使用している間にそのコピーを作成する方法はありますか?Qt shared_ptr signal with 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をヒープに割り当てるのはなぜですか?スタックに作成してください! –
あなたの提案をありがとう、私は間違いなく私はスレッドプロセスを把握して変更します。 – ntmt