Processing files make my program go into non-responding mode. New Process or New thread?
I made an application using Qt where I manipulate Images using the Magick++ library.
The problem is when I'm trying to apply the effects into a list of images, the programs stops responding until the processing is done, I guess that is very normal but I also guess that there should be a solution using new process? concurrency perhaps?
This is the code that is being executed when I'm processing images.
foreach (QFileInfo f, list)
{
Image image;
image.read(qPrintable(f.absoluteFilePath()));
try {
//Apply effects effects
image.addNoise(GaussianNoise);
image.magick("png");
image.rotate(90);
image.write("//users//files//");
}
catch ( Magick::Exception & error)
{
// Displaying any possible errors on the text browser
ui->textBrowser_error->setText(error.what());
}
}
Can anyone show me a code hint that can help me avoid my program by going into non-responding mode?
This is the current solution(Thanks to OneOfOne)
void ClassName::processAll() {
QList<QFileInfo> files = list;
QFuture<void> future = QtConcurrent::map(files, &ClassName::processImage);
}
void ClassName::processImage(QFileInfo & f) {
Image image;
image.read(qPrintable(f.absoluteFilePath()));
try {
// Apply effects effects
image.magick("png");
image.rotate(90);
image.write("//Users//macmini//Desktop//files");
} catch ( Magick::Exception & error) {
// Displaying any possible errors on the text browser.
/* ui->textBrowser_error->setText(error.what()); <- This will not run so I had to commented out */
}
}
This makes my program compile but after that I get a runtime error from apple:
Process: ProgramName [2801]
Path: /Users/macmini/ProgramName-build-desktop/ProgramName.app/Contents/MacOS/ProgramName
Identifier: com.yourcompany.ProgramName
Version: ??? (???)
Code Type: X86-64 (Native)
Parent Process: Qt Creator [2630]
Date/Time: 2010-12-13 18:55:54.381 +0000
OS Version: Mac OS X 10.6.5 (10H574)
Report Version: 6
Interval Since Last Report: 459149 sec
Crashes Since Last Report: 54
Per-App Interval Since Last Report: 59953 sec
Per-App Crashes Since Last Report: 16
Anonymous UUID: 2FA19EA1-D3CE-479B-B074-AB6A297BEFCF
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000010
Crashed Thread: 7
Thread 0: Dispatch queue: com.apple.main-thread
0 com.apple.Foundation 0x00007fff83a9927d -[NSConcreteMapTable objectForKey:] + 1
1 com.apple.AppKit 0x00007fff80f670df -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 1104
2 com.apple.AppKit 0x00007fff80f66ab0 -[NSThemeFrame _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 254
3 com.apple.AppKit 0x00007fff80f63362 -[NSView _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] + 2683
4 com.apple.AppKit 0x00007fff80edcb9a -[NSView displayIfNeeded] + 969
5 QtGui 0x0000000100346cca -[QCocoaWindow displayIfNeeded] + 250
6 com.apple.AppKit 0x00007fff80ed7a46 _handleWindowNeedsDisplay + 678
7 com.apple.CoreFoundation 0x00007fff86644b37 __CFRunLoopDoObservers + 519
8 com.apple.CoreFoundation 0x00007fff86620464 __CFRunLoopRun + 468
9 com.apple.CoreFoundation 0x00007fff8661fdbf CFRunLoopRunSpecific + 575
10 com.apple.HIToolbox 0x00007fff840a291a RunCurrentEventLoopInMode + 333
11 com.apple.HIToolbox 0x00007fff840a267d ReceiveNextEventCommon + 148
12 com.apple.HIToolbox 0x00007fff840a25d8 BlockUntilNextEventMatchingListInMode + 59
13 com.apple.AppKit 0x00007fff80eace64 _DPSNextEvent + 718
14 com.apple.AppKit 0x00007fff80eac7a9 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 155
15 com.apple.AppKit 0x00007fff80e7248b -[NSApplication run] + 395
16 QtGui 0x0000000100354344 QEventDispatcherMac::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 1588
17 QtCore 0x00000001010bde54 QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 68
18 QtCore 0x00000001010be174 QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) + 180
19 QtCore 0x00000001010bf79c QCoreApplication::exec() + 188
20 com.yourcompany.ProgramName 开发者_如何学C 0x00000001000031cb main + 107
21 com.yourcompany.ProgramName 0x0000000100002fb6 _start + 224
22 com.yourcompany.ProgramName 0x0000000100002ed5 start + 33
Thread 1: Dispatch queue: com.apple.libdispatch-manager
0 libSystem.B.dylib 0x00007fff8061a16a kevent + 10
1 libSystem.B.dylib 0x00007fff8061c03d _dispatch_mgr_invoke + 154
2 libSystem.B.dylib 0x00007fff8061bd14 _dispatch_queue_invoke + 185
3 libSystem.B.dylib 0x00007fff8061b83e _dispatch_worker_thread2 + 252
4 libSystem.B.dylib 0x00007fff8061b168 _pthread_wqthread + 353
5 libSystem.B.dylib 0x00007fff8061b005 start_wqthread + 13
Thread 2: com.apple.CFSocket.private
0 libSystem.B.dylib 0x00007fff80644e92 select$DARWIN_EXTSN + 10
1 com.apple.CoreFoundation 0x00007fff86642498 __CFSocketManager + 824
2 libSystem.B.dylib 0x00007fff8063a536 _pthread_start + 331
3 libSystem.B.dylib 0x00007fff8063a3e9 thread_start + 13
Thread 3:
0 libSystem.B.dylib 0x00007fff8061a16a kevent + 10
1 QtCore 0x00000001010aae8a QKqueueFileSystemWatcherEngine::run() + 154
2 QtCore 0x00000001010064cf QThreadPrivate::start(void*) + 175
3 libSystem.B.dylib 0x00007fff8063a536 _pthread_start + 331
4 libSystem.B.dylib 0x00007fff8063a3e9 thread_start + 13
Thread 4:
0 libSystem.B.dylib 0x00007fff8061af8a __workq_kernreturn + 10
1 libSystem.B.dylib 0x00007fff8061b39c _pthread_wqthread + 917
2 libSystem.B.dylib 0x00007fff8061b005 start_wqthread + 13
Thread 5:
0 libSystem.B.dylib 0x00007fff8061af8a __workq_kernreturn + 10
1 libSystem.B.dylib 0x00007fff8061b39c _pthread_wqthread + 917
2 libSystem.B.dylib 0x00007fff8061b005 start_wqthread + 13
Thread 6:
Thread 7 Crashed:
0 libMagickCore.4.dylib 0x000000010144068c gomp_resolve_num_threads + 28
1 libMagickCore.4.dylib 0x00000001012c5d95 AcquirePixelCache + 309
2 libMagickCore.4.dylib 0x000000010137be02 AcquireImage + 370
3 libMagick++.4.dylib 0x00000001002b5057 Magick::ImageRef::ImageRef() + 87
4 libMagick++.4.dylib 0x00000001002ab742 Magick::Image::Image() + 50
5 com.yourcompany.ProgramName 0x00000001000047e1 ProgramName::processImage(QFileInfo&) + 33
6 com.yourcompany.ProgramName 0x0000000100008d1d QtConcurrent::MapKernel<QList<QFileInfo>::iterator, QtConcurrent::FunctionWrapper1<void, QFileInfo&> >::runIteration(QList<QFileInfo>::iterator, int, void*) + 13
7 com.yourcompany.ProgramName 0x0000000100009238 QtConcurrent::MapKernel<QList<QFileInfo>::iterator, QtConcurrent::FunctionWrapper1<void, QFileInfo&> >::runIterations(QList<QFileInfo>::iterator, int, int, void*) + 72
8 com.yourcompany.ProgramName 0x000000010000974d QtConcurrent::IterateKernel<QList<QFileInfo>::iterator, void>::threadFunction() + 573
9 QtCore 0x0000000100fffcb9 QtConcurrent::ThreadEngineBase::run() + 57
10 QtCore 0x0000000101002425 QThreadPoolThread::run() + 117
11 QtCore 0x00000001010064cf QThreadPrivate::start(void*) + 175
12 libSystem.B.dylib 0x00007fff8063a536 _pthread_start + 331
13 libSystem.B.dylib 0x00007fff8063a3e9 thread_start + 13
Thread 8:
0 libSystem.B.dylib 0x00007fff8063a3dc thread_start + 0
Thread 7 crashed with X86 Thread State (64-bit):
rax: 0x0000000000000000 rbx: 0x0000000000000000 rcx: 0x0000000000000000 rdx: 0x0000000000002148
rdi: 0x0000000000000104 rsi: 0x0000000000000000 rbp: 0x0000000116580b10 rsp: 0x0000000116580b00
r8: 0x0000000101b6e000 r9: 0x0000000116580b00 r10: 0x00007fffffe00050 r11: 0x0000000102b6c600
r12: 0x0000000000000000 r13: 0x0000000102b28000 r14: 0x0000000102b82a68 r15: 0x0000000116580d00
rip: 0x000000010144068c rfl: 0x0000000000010297 cr2: 0x0000000000000010
Binary Images:
0x100000000 - 0x100290fe7 +com.yourcompany.ProgramName ??? (???) <688ECF56-94E8-00A4-B958-94612C902F9F> /Users/macmini/ProgramName-build-desktop/ProgramName.app/Contents/MacOS/ProgramName
0x10029b000 - 0x1002dcff7 +libMagick++.4.dylib 5.0.0 (compatibility 5.0.0) <51C6408C-04BD-548B-E2FC-F112252FA2BD> /opt/local/lib/libMagick++.4.dylib
0x100317000 - 0x100ceafef +QtGui 4.7.0 (compatibility 4.7.0) <BD43BAAD-873D-45E8-3605-1E344992BB51> /Library/Frameworks/QtGui.framework/Versions/4/QtGui
0x100f92000 - 0x101217fef +QtCore 4.7.0 (compatibility 4.7.0) <AEA4A1B9-46B8-7621-8D00-555040D89C56> /Library/Frameworks/QtCore.framework/Versions/4/QtCore
0x1012ab000 - 0x101482ff7 +libMagickCore.4.dylib 5.0.0 (compatibility 5.0.0) <25912B2F-55D0-2DA9-DBBF-43986B432952> /opt/local/lib/libMagickCore.4.dylib
0x10151d000 - 0x10162efff +libMagickWand.4.dylib 5.0.0 (compatibility 5.0.0) <80E63BB5-E18A-2BAB-7AFF-D3037AE57427> /opt/local/lib/libMagickWand.4.dylib
0x10164c000 - 0x101679fe7 +liblcms.1.dylib 2.19.0 (compatibility 2.0.0) <2B45C260-15E9-151E-4C8A-05D6B402522B> /opt/local/lib/liblcms.1.dylib
0x101686000 - 0x1016dffff +libtiff.3.dylib 13.4.0 (compatibility 13.0.0) <262BF250-EA47-62E2-D6CB-573CB1E8DD6D> /opt/local/lib/libtiff.3.dylib
0x1016ec000 - 0x101721ff7 +libjpeg.8.dylib 9.2.0 (compatibility 9.0.0) <055E3C7A-A428-2298-816E-79D4279DEE25> /opt/local/lib/libjpeg.8.dylib
0x101728000 - 0x101756ff7 +libfontconfig.1.dylib 6.4.0 (compatibility 6.0.0) <ABE342A5-D352-6D3E-D588-60CEE60396EA> /opt/local/lib/libfontconfig.1.dylib
0x101761000 - 0x101780fef +libexpat.1.dylib 7.2.0 (compatibility 7.0.0) <4F23C4ED-72D8-5478-FBBC-5DC01F8E4752> /opt/local/lib/libexpat.1.dylib
0x101787000 - 0x101807fff +libfreetype.6.dylib 13.1.0 (compatibility 13.0.0) <1DBA7D79-C80E-B3F6-6BEF-5ECBBB318ADE> /opt/local/lib/libfreetype.6.dylib
0x10181c000 - 0x101918fe7 +libiconv.2.dylib 8.0.0 (compatibility 8.0.0) <6907D6DB-2535-7725-484F-74378F42AFED> /opt/local/lib/libiconv.2.dylib
0x101925000 - 0x101933ff7 +libXext.6.dylib 11.0.0 (compatibility 11.0.0) <CB09409A-FEA2-3CF5-769A-127ECCCE2963> /opt/local/lib/libXext.6.dylib
0x101939000 - 0x101986fe7 +libXt.6.dylib 7.0.0 (compatibility 7.0.0) <D780E06E-3060-3D13-BCEC-2F297E840939> /opt/local/lib/libXt.6.dylib
0x10199e000 - 0x1019acfff +libbz2.1.0.dylib 1.0.6 (compatibility 1.0.0) <B2276F4D-BAC5-E9C3-690C-DCC478079569> /opt/local/lib/libbz2.1.0.dylib
0x1019b1000 - 0x1019c5ff7 +libz.1.dylib 1.2.5 (compatibility 1.0.0) <6D767FC2-DF89-6017-4B82-A1E5EB8CEED9> /opt/local/lib/libz.1.dylib
0x1019c9000 - 0x1019cbff7 libclparser.dylib ??? (???) <9985A543-86E9-DA9E-3B97-80CA7AAE84A1>
--Code Removed-- It didnt fit!
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libvMisc.dylib
0x7fff85f7e000 - 0x7fff85ffdfe7 com.apple.audio.CoreAudio 3.2.6 (3.2.6) <1DD64A62-0DE4-223F-F781-B272FECF80F0> /System/Library/Frameworks/CoreAudio.framework/Versions/A/CoreAudio
0x7fff85ffe000 - 0x7fff86083ff7 com.apple.print.framework.PrintCore 6.3 (312.7) <CDFE82DD-D811-A091-179F-6E76069B432D> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Versions/A/PrintCore
0x7fff86084000 - 0x7fff86588fe7 com.apple.VideoToolbox 0.484.20 (484.20) <8B6B82D2-350B-E9D3-5433-51453CDA65B4> /System/Library/PrivateFrameworks/VideoToolbox.framework/Versions/A/VideoToolbox
0x7fff865d4000 - 0x7fff8674bfe7 com.apple.CoreFoundation 6.6.4 (550.42) <770C572A-CF70-168F-F43C-242B9114FCB5> /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
0x7fff8674c000 - 0x7fff8679bff7 com.apple.DirectoryService.PasswordServerFramework 6.0 (6.0) <14FD0978-4BE0-336B-A19E-F388694583EB> /System/Library/PrivateFrameworks/PasswordServer.framework/Versions/A/PasswordServer
0x7fff867e0000 - 0x7fff86821ff7 com.apple.CoreMedia 0.484.20 (484.20) <42F3B74A-F886-33A0-40EE-8399B12BD32A> /System/Library/PrivateFrameworks/CoreMedia.framework/Versions/A/CoreMedia
0x7fff86822000 - 0x7fff868c2fff com.apple.LaunchServices 362.1 (362.1) <2740103A-6C71-D99F-8C6F-FA264546AD8F> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/LaunchServices
0x7fff868c3000 - 0x7fff868e4fff libresolv.9.dylib 41.0.0 (compatibility 1.0.0) <6993F348-428F-C97E-7A84-7BD2EDC46A62> /usr/lib/libresolv.9.dylib
0x7fff868e5000 - 0x7fff86d28fef libLAPACK.dylib 219.0.0 (compatibility 1.0.0) <0CC61C98-FF51-67B3-F3D8-C5E430C201A9> /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLAPACK.dylib
0x7fff86d3f000 - 0x7fff86d55fe7 com.apple.MultitouchSupport.framework 207.10 (207.10) <1828C264-A54A-7FDD-FE1B-49DDE3F50779> /System/Library/PrivateFrameworks/MultitouchSupport.framework/Versions/A/MultitouchSupport
0x7fff86d56000 - 0x7fff86da7fef com.apple.HIServices 1.8.1 (???) <BE479ABF-3D27-A5C7-800E-3FFC1731767A> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/HIServices
0x7fff86de0000 - 0x7fff86e03fff com.apple.opencl 12.3 (12.3) <D30A45FC-4520-45AF-3CA5-092313DB5D54> /System/Library/Frameworks/OpenCL.framework/Versions/A/OpenCL
0x7fff86e04000 - 0x7fff86ebafff libobjc.A.dylib 227.0.0 (compatibility 1.0.0) <F206BE6D-8777-AE6C-B367-7BEA76C14241> /usr/lib/libobjc.A.dylib
0x7fff86f54000 - 0x7fff86f6afff com.apple.ImageCapture 6.0.1 (6.0.1) <09ABF2E9-D110-71A9-4A6F-8A61B683E936> /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/ImageCapture.framework/Versions/A/ImageCapture
0x7fff86f6b000 - 0x7fff86f9cfff libGLImage.dylib ??? (???) <57DA0064-4581-62B8-37A8-A07ADEF46EE2> /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLImage.dylib
0x7fff86f9d000 - 0x7fff86fa1ff7 libCGXType.A.dylib 545.0.0 (compatibility 64.0.0) <63F77AC8-84CB-0C2F-8D2B-190EE5CCDB45> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreGraphics.framework/Versions/A/Resources/libCGXType.A.dylib
0x7fff86fa2000 - 0x7fff86fc7ff7 com.apple.CoreVideo 1.6.2 (45.6) <E138C8E7-3CB6-55A9-0A2C-B73FE63EA288> /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo
0x7fff86fd4000 - 0x7fff86fedfff com.apple.CFOpenDirectory 10.6 (10.6) <CCF79716-7CC6-2520-C6EB-A4F56AD0A207> /System/Library/Frameworks/OpenDirectory.framework/Versions/A/Frameworks/CFOpenDirectory.framework/Versions/A/CFOpenDirectory
0x7fff86fee000 - 0x7fff870e6ff7 libiconv.2.dylib 7.0.0 (compatibility 7.0.0) <7E4ADB5A-CC77-DCFD-3E54-2F35A2C8D95A> /usr/lib/libiconv.2.dylib
0x7fff870e7000 - 0x7fff872a5fff libicucore.A.dylib 40.0.0 (compatibility 1.0.0) <781E7B63-2AD0-E9BA-927C-4521DB616D02> /usr/lib/libicucore.A.dylib
0x7fff872a6000 - 0x7fff87643fe7 com.apple.QuartzCore 1.6.3 (227.34) <215222AF-B30A-7CE5-C46C-1A766C1D1D2E> /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore
0x7fff87644000 - 0x7fff87646fff com.apple.print.framework.Print 6.1 (237.1) <CA8564FB-B366-7413-B12E-9892DA3C6157> /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/Print.framework/Versions/A/Print
0x7fff87682000 - 0x7fff8769dff7 com.apple.openscripting 1.3.1 (???) <FD46A0FE-AC79-3EF7-AB4F-396D376DDE71> /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/OpenScripting.framework/Versions/A/OpenScripting
0x7fff8769e000 - 0x7fff8769ffff liblangid.dylib ??? (???) <EA4D1607-2BD5-2EE2-2A3B-632EEE5A444D> /usr/lib/liblangid.dylib
0x7fff876a0000 - 0x7fff876bdff7 libPng.dylib ??? (???) <14043CBC-329F-4009-299E-DEE411E16134> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/Resources/libPng.dylib
0x7fff87901000 - 0x7fff8794bff7 com.apple.Metadata 10.6.3 (507.12) <9231045A-E2E3-B0C2-C81A-92C9EA98A4DF> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/Metadata.framework/Versions/A/Metadata
0x7fff87af2000 - 0x7fff87b01fff com.apple.NetFS 3.2.1 (3.2.1) <FF21DB1E-F425-1005-FB70-BC19CAF4006E> /System/Library/Frameworks/NetFS.framework/Versions/A/NetFS
0x7fff87b11000 - 0x7fff87b8ffff com.apple.CoreText 3.5.0 (???) <4D5C7932-293B-17FF-7309-B580BB1953EA> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreText.framework/Versions/A/CoreText
0x7fff87ba9000 - 0x7fff87bf8fef libTIFF.dylib ??? (???) <AE9DC484-1382-F7AD-FE25-C28082FCB5D9> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/Resources/libTIFF.dylib
0x7fff87bf9000 - 0x7fff87cb2fff libsqlite3.dylib 9.6.0 (compatibility 9.0.0) <2C5ED312-E646-9ADE-73A9-6199A2A43150> /usr/lib/libsqlite3.dylib
0x7fff87d3d000 - 0x7fff87d4eff7 libz.1.dylib 1.2.3 (compatibility 1.0.0) <FB5EE53A-0534-0FFA-B2ED-486609433717> /usr/lib/libz.1.dylib
0x7fff87ee8000 - 0x7fff88026fff com.apple.CoreData 102.1 (251) <32233D4D-00B7-CE14-C881-6BF19FD05A03> /System/Library/Frameworks/CoreData.framework/Versions/A/CoreData
0x7fff88027000 - 0x7fff88027ff7 com.apple.CoreServices 44 (44) <DC7400FB-851E-7B8A-5BF6-6F50094302FB> /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices
0x7fff88028000 - 0x7fff88057ff7 com.apple.quartzfilters 1.6.0 (1.6.0) <9CECB4FC-1CCF-B8A2-B935-5888B21CBEEF> /System/Library/Frameworks/Quartz.framework/Versions/A/Frameworks/QuartzFilters.framework/Versions/A/QuartzFilters
0x7fff88058000 - 0x7fff8806afe7 libsasl2.2.dylib 3.15.0 (compatibility 3.0.0) <76B83C8D-8EFE-4467-0F75-275648AFED97> /usr/lib/libsasl2.2.dylib
0x7fff880be000 - 0x7fff881e4fff com.apple.audio.toolbox.AudioToolbox 1.6.5 (1.6.5) <B51023BB-A5C9-3C65-268B-6B86B901BB2C> /System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox
0x7fff881e5000 - 0x7fff881ebfff libCGXCoreImage.A.dylib 545.0.0 (compatibility 64.0.0) <4EE16374-A094-D542-5BC5-7E846D0CE56E> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreGraphics.framework/Versions/A/Resources/libCGXCoreImage.A.dylib
0x7fff881ec000 - 0x7fff881eefff libRadiance.dylib ??? (???) <76438F90-DD4B-9941-9367-F2DFDF927876> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/Resources/libRadiance.dylib
0x7fff881f5000 - 0x7fff881f5ff7 com.apple.Carbon 150 (152) <19B37B7B-1594-AD0A-7F14-FA2F85AD7241> /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon
0x7fff881f6000 - 0x7fff88233ff7 libFontRegistry.dylib ??? (???) <8C69F685-3507-1B8F-51AD-6183D5E88979> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ATS.framework/Versions/A/Resources/libFontRegistry.dylib
0x7fff88234000 - 0x7fff88237ff7 com.apple.securityhi 4.0 (36638) <38935851-09E4-DDAB-DB1D-30ADC39F7ED0> /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/SecurityHI.framework/Versions/A/SecurityHI
0x7fff88238000 - 0x7fff883a7fe7 com.apple.QTKit 7.6.6 (1756) <250AB242-816D-9F5D-94FB-18BF2AE9AAE7> /System/Library/Frameworks/QTKit.framework/Versions/A/QTKit
0x7fff8845f000 - 0x7fff88569ff7 com.apple.MeshKitIO 1.1 (49.2) <F296E151-80AE-7764-B969-C2050DF26BFE> /System/Library/PrivateFrameworks/MeshKit.framework/Versions/A/Frameworks/MeshKitIO.framework/Versions/A/MeshKitIO
0x7fff8856a000 - 0x7fff8856eff7 libmathCommon.A.dylib 315.0.0 (compatibility 1.0.0) <95718673-FEEE-B6ED-B127-BCDBDB60D4E5> /usr/lib/system/libmathCommon.A.dylib
0x7fff885b3000 - 0x7fff885c4fff com.apple.DSObjCWrappers.Framework 10.6 (134) <3C08225D-517E-2822-6152-F6EB13A4ADF9> /System/Library/PrivateFrameworks/DSObjCWrappers.framework/Versions/A/DSObjCWrappers
0x7fff885c5000 - 0x7fff88690fe7 ColorSyncDeprecated.dylib 4.6.0 (compatibility 1.0.0) <3C223A94-EF14-28C5-844B-C25DFC87FB42> /System/Library/Frameworks/ApplicationServices.framework/Frameworks/ColorSync.framework/Versions/A/Resources/ColorSyncDeprecated.dylib
0x7fff88691000 - 0x7fff887b2fe7 libcrypto.0.9.8.dylib 0.9.8 (compatibility 0.9.8) <48AEAFE1-21F4-B3C8-4199-35AD5E8D0613> /usr/lib/libcrypto.0.9.8.dylib
0x7fff887b3000 - 0x7fff888cafef libxml2.2.dylib 10.3.0 (compatibility 10.0.0) <EE067D7E-15B3-F043-6FBD-10BA31FE76C7> /usr/lib/libxml2.2.dylib
0x7fff888cb000 - 0x7fff888d0fff libGIF.dylib ??? (???) <9A2723D8-61F9-6D65-D254-4F9273CDA54A> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/Resources/libGIF.dylib
0x7fff88c15000 - 0x7fff88c58ff7 libRIP.A.dylib 545.0.0 (compatibility 64.0.0) <7E30B5F6-99FD-C716-8670-5DD4B4BAED72> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreGraphics.framework/Versions/A/Resources/libRIP.A.dylib
0x7fff88c59000 - 0x7fff88ca2fef libGLU.dylib ??? (???) <EB4255DD-A9E5-FAD0-52A4-CCB4E792B86F> /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLU.dylib
0x7fff88ca3000 - 0x7fff88ceffff libauto.dylib ??? (???) <F7221B46-DC4F-3153-CE61-7F52C8C293CF> /usr/lib/libauto.dylib
0x7fff88cf0000 - 0x7fff88d6dfef libstdc++.6.dylib 7.9.0 (compatibility 7.0.0) <35ECA411-2C08-FD7D-11B1-1B7A04921A5C> /usr/lib/libstdc++.6.dylib
0x7fff88d6e000 - 0x7fff88d82ff7 com.apple.speech.synthesis.framework 3.10.35 (3.10.35) <621B7415-A0B9-07A7-F313-36BEEDD7B132> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/SpeechSynthesis.framework/Versions/A/SpeechSynthesis
0x7fff88d83000 - 0x7fff88d84ff7 com.apple.TrustEvaluationAgent 1.1 (1) <74800EE8-C14C-18C9-C208-20BBDB982D40> /System/Library/PrivateFrameworks/TrustEvaluationAgent.framework/Versions/A/TrustEvaluationAgent
0x7fff88d85000 - 0x7fff88df1ff7 com.apple.CorePDF 1.3 (1.3) <6770FFB0-DEA0-61E0-3520-4B95CCF5D1CF> /System/Library/PrivateFrameworks/CorePDF.framework/Versions/A/CorePDF
0x7fff88e6f000 - 0x7fff88e76fff com.apple.OpenDirectory 10.6 (10.6) <4200CFB0-DBA1-62B8-7C7C-91446D89551F> /System/Library/Frameworks/OpenDirectory.framework/Versions/A/OpenDirectory
0x7fff88e77000 - 0x7fff890b2fef com.apple.imageKit 2.0.3 (1.0) <5D18C246-303A-6580-9DC9-79BE79467C95> /System/Library/Frameworks/Quartz.framework/Versions/A/Frameworks/ImageKit.framework/Versions/A/ImageKit
0x7fff890b3000 - 0x7fff890b3ff7 com.apple.Accelerate.vecLib 3.6 (vecLib 3.6) <DA9BFF01-40DF-EBD5-ABB7-787DAF2D77CF> /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/vecLib
0x7fff890b4000 - 0x7fff890fbfff com.apple.QuickLookFramework 2.3 (327.6) <11DFB135-24A6-C0BC-5B97-ECE352A4B488> /System/Library/Frameworks/QuickLook.framework/Versions/A/QuickLook
0x7fff890fc000 - 0x7fff89127ff7 libxslt.1.dylib 3.24.0 (compatibility 3.0.0) <87A0B228-B24A-C426-C3FB-B40D7258DD49> /usr/lib/libxslt.1.dylib
0x7fffffe00000 - 0x7fffffe01fff libSystem.B.dylib ??? (???) <71E6D4C9-F945-6EC2-998C-D61AD590DAB6> /usr/lib/libSystem.B.dylib
Model: Macmini2,1, BootROM MM21.009A.B00, 2 processors, Intel Core 2 Duo, 2 GHz, 2 GB, SMC 1.19f0
Graphics: Intel GMA 950, GMA 950, Built-In, spdisplays_integrated_vram
Memory Module: global_name
AirPort: spairport_wireless_card_type_airport_extreme (0x168C, 0x86), Atheros 5424: 2.1.14.5
Bluetooth: Version 2.3.8f7, 2 service, 19 devices, 1 incoming serial ports
Network Service: Ethernet, Ethernet, en0
Serial ATA Device: Hitachi HTS541612J9SA00, 111.79 GB
Parallel ATA Device: PIONEER DVD-RW DVR-K06
USB Device: A4 TECH USB2.0 PC Camera J, 0x0ac8 (Vimicro Corporation), 0xc40a, 0xfd600000
USB Device: 2.4Ghz wireless combo sets, 0x04fc (SUNPLUS TECHNOLOGY CO., LTD.), 0x05d8, 0x1d100000
USB Device: Bluetooth USB Host Controller, 0x05ac (Apple Inc.), 0x8205, 0x7d100000
USB Device: IR Receiver, 0x05ac (Apple Inc.), 0x8240, 0x7d200000
You can create a processing function and use Qt4's QtConcurrent::map or QtConcurrent::run. Also check QFuture.
Example:
void processImage(QFileInfo & f) {
Image image;
image.read(qPrintable(f.absoluteFilePath()));
try {
//Apply effects effects
image.addNoise(GaussianNoise);
image.magick("png");
image.rotate(90);
image.write("//users//files//");
} catch ( Magick::Exception & error) {
// Displaying any possible errors on the text browser
ui->textBrowser_error->setText(error.what());
}
}
void processAll() {
const QList<QFileInfo> files = getFilesList();
QFuture<void> future = QtConcurrent::map(files, processImage);
//do something with future
}
edit :: Changed QFile to QFileInfo.
I don't know how it works with Qt, but on Windows (WINAPI), a user interface stops responding when the message queue for that window goes unanswered for a period of time. Here's such a loop for completeness:
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
// if you don't handle this "fast" enough, windows "whites" you out
switch ( msg )
{
case WM_COMMAND:
// ...
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
This happens if you're doing some heavy lifting processing one of those messages. That's what happens when a Windows window turns white, or grey, or whatever.
I've never worked with GUIs on Linux (I tend to write cli stuff) but I imagine it's the same principle.
You basically want to break out a new thread. However, how you do this is the interesting part.
If your app is linux-only, you could use pthreads or you could do:
pid_t result = fork()
if ( result == 0 )
{
// child
}
elseif ( result > 0 )
{
// parent, result = child process id.
}
else
{
// error. result == -1.
}
As I understand it, there is little cost difference between a thread and a process on Linux.
However, some GUI frameworks provide their own thread wrappers I believe (wxWidgets comes to mind) for portability reasons. You might want to go with that if you're looking for a cross platform solution. I don't know if Qt provides such an option. However, before anyone else says it, Boost probably does.
精彩评论