Limereport frecuent crash when called from other Thread
Greetings to all the friends.
I would like to report a Bug in Limereport, when you call report->previewReport(), report->printToPDF(PDFName);
Crash with the following error: QObject::connect: Cannot queue arguments of type 'LimeReport::CallbackInfo' (Make sure 'LimeReport::CallbackInfo' is registered using qRegisterMetaType().)
If limereport is called from mainwindow thread or is not created as pointer there is no problem but when you initialise Limereport from QRunnable with:
LimeReport::ReportEngine *report = new LimeReport::ReportEngine(nullptr);
It will crash!
Regards, Alonso Murillo
Hi! Unfortunately, LimeReport isn't thread-safe you shouldn't run it in another thread.
Thank you for your prompt reply Alex, code is code no matter in which thread is runned, I am creating limereport object in the same thread I am calling it so there is no reason why would not work, what is mandatory in order to work correctly?
Having a parent like this?: LimeReport::ReportEngine report(this);
Or is it that Limereport does not work properly when runned on the heap like this: LimeReport::ReportEngine *report = new LimeReport::ReportEngine(this);
Regards. Alonso Murillo.
Is there anything I can do to help to make it thread safe?
It's hard to say :) Some parts of LimeReport would be thread-safe, rendering for example. Possible in the future we could make some changes which will allow as to do rendering the report in a different thread.
On all the test I ran I found that when this line is called: report.printToPDF(TargetFileName);
My application crash, but sometimes does not crash, so I think maybe you can add WaitForFinished function to make sure that Limereport complete all the process to render, save and cleaning.
I found this website: https://www.nuomiphp.com/eplan/en/17307.html Reads: The problem has nothing to do with the threads but QPixmap is not thread-safe and should not be manipulated from another thread as the docs points out:
GUI Thread and Worker Thread As mentioned, each program has one thread when it is started. This thread is called the "main thread" (also known as the "GUI thread" in Qt applications). The Qt GUI must run in this thread. All widgets and several related classes, for example QPixmap, don't work in secondary threads. A secondary thread is commonly referred to as a "worker thread" because it is used to offload processing work from the main thread.
Instead you should use QImage that is optimized for I/O operation as the docs points out:
Qt provides four classes for handling image data: QImage, QPixmap, QBitmap and QPicture. QImage is designed and optimized for I/O, and for direct pixel access and manipulation, while QPixmap is designed and optimized for showing images on screen. QBitmap is only a convenience class that inherits QPixmap, ensuring a depth of 1. The isQBitmap() function returns true if a QPixmap object is really a bitmap, otherwise returns false. Finally, the QPicture class is a paint device that records and replays QPainter commands.
Lime report is very, very good, but would be great if could be run in other thread, because sometimes you need to render several pages may take considerable amount of time, so running such task would allow the user to perform other tasks while Limereport work in the background, that would be Wonderful.
I hope that help you and if I can help you with anything else I will be more than happy to assist.
Regards, Alonso Murillo.