Results 1 to 3 of 3

Thread: [Solved] QMainWindow subclass not receiving winEvents unless QMessageBox is called

  1. #1
    Join Date
    Jul 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default [Solved] QMainWindow subclass not receiving winEvents unless QMessageBox is called

    Hello all,

    I'm new to Qt (4.8.1 for Desktop + MSVC2010) and also just starting to get a handle on C++, and I'm trying to interact with a 3rd party driver DLL that sends Events to a HWDN (which I attempt to set via MainWindow::effectiveWinId() ). This has been working, though apparently only by chance, as inside my MainWindow, before setting said HWND, I called created a QMessageBox.
    My MainWindow is a regular UI-Designer subclassed QMainWindow:

    Qt Code:
    1. namespace Ui {
    2. class MainWindow;
    3. }
    4.  
    5. class MainWindow : public QMainWindow
    6. {
    7. Q_OBJECT
    8.  
    9. public:
    10. explicit MainWindow(QWidget *parent = 0);
    11. virtual bool winEvent( MSG* message, long* result );
    12. ~MainWindow();
    13.  
    14. private:
    15. Ui::MainWindow *ui;
    16. ....
    17. void installmessages();
    18.  
    19. private slots:
    20. void on_freezeButton_clicked();
    21.  
    22. };
    To copy to clipboard, switch view to plain text mode 


    The code in MainWindow::installmessages();
    Qt Code:
    1. qDebug() << "before";
    2. qDebug() << MainWindow::effectiveWinId() ;
    3.  
    4. // *
    5. qDebug() << "messagebox";
    6. QMessageBox::information( this,
    7. tr("Messagebox title"),
    8. tr("WinID %1").arg( (long) MainWindow::effectiveWinId() )
    9. );
    10.  
    11. // */
    12. qDebug() << "after";
    13. qDebug() << MainWindow::effectiveWinId() ;
    14.  
    15. ....
    16.  
    17. [call to proprietary library with MainWindow::effectiveWinId() as parameter]
    To copy to clipboard, switch view to plain text mode 


    results in this output

    Qt Code:
    1. before
    2. 0x0
    3. messagebox [the output is "WinID 0"]
    4. after
    5. 0x17046a
    To copy to clipboard, switch view to plain text mode 

    So with message box, my program works since I get a valid ID and thus receive messages.
    Why is the WinID valid only when the MessageBox is run?
    Last edited by fruchtquark; 25th July 2012 at 14:32.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QMainWindow subclass not receiving winEvents unless QMessageBox is called

    in which method are your qDebug() outputs?
    And show the rest, the code (where the debug outputs are) only shows that you are outputing debug messages - show the rest of the code there.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jul 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMainWindow subclass not receiving winEvents unless QMessageBox is called

    Apparently windows / widgets don't get a system window ID by default and are called non-native or alien.
    While setAttribute(Qt::WA_NativeWindow); did not have an effect, winId did: http://qt-project.org/doc/qt-4.8/qwidget.html#winId

    I'm not sure if this is a workaround or a permanent solution, so any comments are still welcome..
    Last edited by fruchtquark; 25th July 2012 at 12:03.

Similar Threads

  1. Replies: 2
    Last Post: 25th June 2012, 19:14
  2. paintEvent not getting called with QMainWindow
    By DiamonDogX in forum Qt Programming
    Replies: 12
    Last Post: 15th June 2011, 22:23
  3. Replies: 5
    Last Post: 10th August 2010, 04:39
  4. Replies: 2
    Last Post: 23rd May 2008, 13:22
  5. QMainWindow not receiving QResizeEvent
    By brcain in forum Qt Programming
    Replies: 1
    Last Post: 28th September 2006, 06:11

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.