Results 1 to 7 of 7

Thread: QFileDialog prevents app from closing

  1. #1
    Join Date
    Jul 2009
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default QFileDialog prevents app from closing

    Using QFileDialog::getOpenFileName(...) anywhere in my mainWindow prevents the application from closing when the mainWindow is ultimately closed; it continues to run in the background until I stop it through task manager or, if running in Qt Creator, click the red square.

    QColorDialog and QMessageBox do not cause this problem, so it is not merely caused by opening a new window.

    I have tried connecting both the application's lastWindowClosed() signal and the mainWindow's destroyed() signal to the application's quit() slot, to no effect.

    I defined a destructor for my mainWindow and verified that the code there executes when the user clicks the red X in the corner. I even put the command this->destroy() in that destructor, again to no effect.

    I would appreciate advice if anyone has encountered this or a similar issue.

  2. #2
    Join Date
    Jul 2009
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFileDialog prevents app from closing

    A bizarre twist: I found that the problem goes away if I remove from the project a small file for converting between QImages and IPLImages (used in OpenCV)

    The file, which i found online, does not do anything that seems like it should be relevant to QFileDialog, here is the header:

    Qt Code:
    1. #ifndef QTIPL_H
    2. #define QTIPL_H
    3. #include <QImage>
    4. #include <highgui.h>
    5.  
    6. IplImage qtToCv(QImage* qImage);
    7. QImage cvToQt(IplImage* iplImage);
    8.  
    9. #endif // QTIPL_H
    To copy to clipboard, switch view to plain text mode 


    and cpp:
    Qt Code:
    1. #include "qtIPL.h"
    2.  
    3. IplImage qtToCv(QImage* qImage)
    4. {
    5. IplImage* cvImage;
    6. cvImage = cvCreateImageHeader(cvSize(qImage->width(), qImage->height()), IPL_DEPTH_8U, 4);
    7. cvImage->imageData = (char*)qImage->bits();
    8. IplImage* colorImage = cvCreateImage( cvGetSize(cvImage), 8, 3 );
    9. cvConvertImage( cvImage, colorImage, 0 );
    10.  
    11. return *colorImage;
    12. }
    13.  
    14. QImage cvToQt(IplImage* iplImage)
    15. {
    16. if(!cvSaveImage("tmpImg.bmp", iplImage)) printf("Could not save: tmpImg.bmp in cvToQt");
    17. QImage img("tmpImg.bmp");
    18. }
    To copy to clipboard, switch view to plain text mode 


    if anyone sees something wrong with this (or can recommend a similar way to convert between these two image formats) please let me know
    Last edited by jpn; 15th July 2009 at 22:10. Reason: missing [code] tags

  3. #3
    Join Date
    Jul 2009
    Location
    Finland
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFileDialog prevents app from closing

    Hi

    I am having this same problem at the moment also, and I am also using OpenCV. It is indeed bizarre that the problem could come from something that has nothing to do with QFileDialog. Not sure if this has anything to do with it, but is your app multithreaded? (Mine is.)

  4. #4
    Join Date
    Jul 2009
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFileDialog prevents app from closing

    No, no multithreading (unless Qt does some behind the scenes for event listeners and such)

  5. #5
    Join Date
    Jul 2009
    Location
    Finland
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFileDialog prevents app from closing

    I managed to narrow down the problem. There seems to be some incompatibility with the highgui and/or cxcore libraries from Opencv and the QFileDialog::getOpenFileName function (and who knows, possibly some others too).

    I attached the qtIPL files you posted to a test project and was able to reproduce the problem. I did not even have to include the files in code, just having the files in the project was enough to cause the problem. Something is happening when the compiler is linking these libraries which causes the problem. Removing the files from the project and rebuilding removes the problem. I am using Visual Studio 2008. Any ideas are welcome.

  6. #6
    Join Date
    Jul 2009
    Location
    Finland
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFileDialog prevents app from closing

    It seems the highgui library is the problem. I modified the qtIPL code to only use the cxcore library and the problem went away. This I think solves your problem, but I'm using too many highgui functions to get rid of them so it doesn't really help me. So I guess then that when integrating OpenCV with Qt one should stay away from the highgui functions. Here is the modified code:

    Qt Code:
    1. #ifndef QTIPL_H
    2. #define QTIPL_H
    3. #include <QImage>
    4. #include <cxcore.h>
    5.  
    6. IplImage qtToCv(QImage* qImage);
    7. QImage cvToQt(IplImage* iplImage);
    8.  
    9. #endif // QTIPL_H
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include "qtIPL.h"
    2.  
    3. IplImage qtToCv(QImage* qImage)
    4. {
    5. IplImage* cvImage;
    6. cvImage = cvCreateImageHeader(cvSize(qImage->width(), qImage->height()), IPL_DEPTH_8U, 4);
    7. cvImage->imageData = (char*)qImage->bits();
    8. IplImage* colorImage = cvCreateImage( cvGetSize(cvImage), 8, 3 );
    9. cvCopy( cvImage, colorImage ); //cvConvertImage was just doing a copy
    10.  
    11. return *colorImage;
    12. }
    13.  
    14. QImage cvToQt(IplImage* iplImage)
    15. {
    16. cvSave( "tmpImg.bmp", iplImage );
    17. //do something to check if succesful
    18. QImage img("tmpImg.bmp");
    19.  
    20. return img;
    21. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jul 2009
    Location
    Finland
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFileDialog prevents app from closing

    More info. It is actually only when using some Qt function that accesses the OS file system GUI/dialog (hmm, probably any OS GUI/dialog for that matter) that the Highgui library causes the program to hang when closing. I tried using QTreeView and QDirModel to work around the QFileDialog::getOpenFileName() function, but QDirModel also caused the same problem. But then I tried QTreeWidget and QDir to create the items and it worked. No more hang up when closing.

Similar Threads

  1. Check for invalid file name in QFileDialog
    By darren in forum Qt Programming
    Replies: 2
    Last Post: 7th November 2008, 14:43
  2. QFileDialog in Qt designer
    By tpf80 in forum Qt Tools
    Replies: 1
    Last Post: 17th May 2007, 00:41
  3. QFileDialog Mac / PC
    By hey in forum Qt Programming
    Replies: 3
    Last Post: 26th April 2007, 18:23
  4. ActiveWindow changes after closing QFileDialog
    By mischi in forum Qt Programming
    Replies: 3
    Last Post: 13th July 2006, 12:45
  5. copy file/s from QFileDialog
    By raphaelf in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 14:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.