@@ -490,9 +490,30 @@ void AscentViewer::changeToPhoto(int photoIndex, bool saveDescriptionFirst)
490
490
}
491
491
else {
492
492
QString filepath = photos.at (currentPhotoIndex).filepath ;
493
+ QImageReader::setAllocationLimit (512 );
494
+
495
+ // Set up error message capturing
496
+ imageLoadErrorMessage.clear ();
497
+ qInstallMessageHandler ([] (QtMsgType type, const QMessageLogContext& context, const QString& msg) {
498
+ Q_UNUSED (type);
499
+ Q_UNUSED (context);
500
+ if (!msg.startsWith (" QImageIOHandler: " )) return ;
501
+ QString trimmedMessage = msg;
502
+ trimmedMessage.remove (" QImageIOHandler: " );
503
+ AscentViewer::imageErrorMessageOccurred (trimmedMessage);
504
+ });
505
+
493
506
QImageReader reader = QImageReader (filepath);
494
507
reader.setAutoTransform (true );
495
508
QImage image = reader.read ();
509
+
510
+ // Fetch printed error message
511
+ qInstallMessageHandler (nullptr );
512
+ QString extraErrorMessage = imageLoadErrorMessage;
513
+ imageLoadErrorMessage.clear ();
514
+ if (!extraErrorMessage.isEmpty ()) {
515
+ extraErrorMessage = tr (" \n More details: %1." ).arg (extraErrorMessage);
516
+ }
496
517
497
518
if (!image.isNull ()) { // Image loaded
498
519
// Prepare image frame to show image
@@ -504,8 +525,9 @@ void AscentViewer::changeToPhoto(int photoIndex, bool saveDescriptionFirst)
504
525
QString labelText = tr (
505
526
" This image file cannot be shown:\n %1"
506
527
" \n Reason: %2."
528
+ " %3"
507
529
" \n\n You can remove the image, replace the file, or mass relocate image files in the whole database." )
508
- .arg (filepath, reader.errorString ()); // Error string is already translated
530
+ .arg (filepath, reader.errorString (), extraErrorMessage ); // Error string is already translated
509
531
imageErrorLabel->setText (labelText);
510
532
511
533
// Show image error box
@@ -1011,6 +1033,20 @@ void AscentViewer::handle_filesDropped(QStringList filepaths)
1011
1033
1012
1034
1013
1035
1036
+ /* *
1037
+ * Globally accessible static function for receiving error messages from QImageReader.
1038
+ *
1039
+ * This function is used because qInstallMessageHandler() does not allow capturing in lambdas.
1040
+ *
1041
+ * @param message The error message with its prefix already removed.
1042
+ */
1043
+ void AscentViewer::imageErrorMessageOccurred (const QString& message)
1044
+ {
1045
+ imageLoadErrorMessage = message;
1046
+ }
1047
+
1048
+
1049
+
1014
1050
/* *
1015
1051
* Spawns the info area context menu at the given position and controls the enabled state of its
1016
1052
* actions.
0 commit comments