Results 1 to 8 of 8

Thread: commitData doesn't seem to be called...

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2008
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default commitData doesn't seem to be called...

    Hello everyone.
    This is my first post here and I'm fairly new to C++ and Qt programming.
    Here's my problem.
    I'm working on an application written in Qt4.4.0 in MS windows.
    The application allows only one instance and uses a file that, if present, means an instance is running. So, I create this file on application startup and delete it on application exit.
    This works fine when the program ends by user interaction but it's not working when I close a windows session, or by a windows shutdown.

    I made a simple testcase to illustrate my problem, so that any willing soul can give it a shot and point me some sort of error that I'm making here....

    This is main.cpp
    Qt Code:
    1. #include <QDebug>
    2. #include "Application.h"
    3.  
    4. int main( int argc , char *argv[] ) {
    5. Application myApp(argc , argv);
    6.  
    7. return myApp.exec();
    8. }
    To copy to clipboard, switch view to plain text mode 

    and here's my app class, subclassed from QApplication, so that I could reimplement commitData():
    Application.h:
    Qt Code:
    1. #ifndef __APPLICATION_H__
    2. #define __APPLICATION_H__
    3. #include <QFile>
    4. #include <QApplication>
    5. #include <QSessionManager>
    6.  
    7. class Application: public QApplication {
    8. Q_OBJECT
    9. private:
    10. QFile lockFile;
    11. public:
    12. Application( int argc , char *argv[] );
    13. void commitData( QSessionManager &manager);
    14.  
    15. public slots:
    16. void bailout(QSessionManager &manager);
    17. };
    18.  
    19. #endif // __APPLICATION_H__
    To copy to clipboard, switch view to plain text mode 

    and Application.cpp:
    Qt Code:
    1. #include <QDebug>
    2. #include <QApplication>
    3. #include <QSessionManager>
    4. #include "Application.h"
    5.  
    6. Application::Application( int argc , char *argv[] ): QApplication( argc , argv ) {
    7. lockFile.setFileName( QString( "%1/instance.lock" ).arg( qApp->applicationDirPath() ) );
    8. lockFile.open(QIODevice::WriteOnly);
    9.  
    10. connect(
    11. this , SIGNAL(commitDataRequest(QSessionManager&))
    12. , this , SLOT(bailout(QSessionManager&))
    13. , Qt::DirectConnection
    14. );
    15. }
    16.  
    17. void Application::commitData(QSessionManager& manager) {
    18. qDebug() << "Commiting data :-)";
    19. lockFile.close();
    20. lockFile.remove();
    21. manager.release();
    22. }
    23.  
    24. void Application::bailout(QSessionManager &manager) {
    25. qDebug() << "I'm bailing out!";
    26. manager.release();
    27. }
    To copy to clipboard, switch view to plain text mode 

    This is the project file, in case it's usefull...
    Qt Code:
    1. TEMPLATE = app
    2. SOURCES += main.cpp Application.cpp
    3. CONFIG += console warn_on
    4. HEADERS += Application.h
    To copy to clipboard, switch view to plain text mode 

    I'm using Qt 4.4.0 on windows with Mingw gcc 3.4.5
    Altough I (think that I) reimplemented commitData() as mentioned in the docs, it seems to never be called.
    I launched the program in a cmd.exe terminal, and also from the explorer shell, then I close my session, I see the application finishes ( terminal returns to prompt ), but no messages are printed, and the lock file isn't deleted at all. Tested with closeing session and with windows shutdown.

    What am I doing wrong here? I suppose it must be some silly mistake, but I'm not experienced enough to detect it. Is commitData() actually reimplemented correctly, or is it not being called at all??

    Any help would be very, very apreciated at this point...

    cheers,
    --to
    Last edited by tone; 8th September 2008 at 16:40. Reason: typos :-)

Similar Threads

  1. setSceneRect not being called properly?
    By bjh in forum Qt Programming
    Replies: 7
    Last Post: 12th July 2009, 19:42
  2. Replies: 1
    Last Post: 7th August 2008, 13:46
  3. QWidget::resizeEvent is not called
    By maximAL in forum Qt Programming
    Replies: 9
    Last Post: 3rd February 2008, 16:41
  4. Replies: 3
    Last Post: 20th February 2007, 13:02
  5. QWidget::paintEngine() should no longer be called
    By Greeny in forum Qt Programming
    Replies: 7
    Last Post: 7th February 2007, 10:12

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.