Hi all,
I have a dock widget custom class who use a custom titlebar.
All works fine but when I close the application and one dock is floating, I have a crash.
Without the custom titlebar I have 0 crash, I tried to find but all looks fine to me.
Code :
Qt Code:
  1. CDockWidget::CDockWidget( const QString& Title, QWidget* Parent ) :
  2. QDockWidget( Title, Parent )
  3. {
  4. m_Titlebar = new CTitlebarWidget( this );
  5. setTitleBarWidget( m_Titlebar );
  6. installEventFilter( this );
  7. }
  8.  
  9. bool CDockWidget::eventFilter( QObject* watched, QEvent* event )
  10. {
  11. switch( event->type() )
  12. {
  13. case QEvent::WindowTitleChange :
  14. {
  15. m_Titlebar->SetTitle( windowTitle() );
  16. return true;
  17. }
  18.  
  19. case QEvent::NonClientAreaMouseButtonDblClick :
  20. {
  21. if( isMaximized() )
  22. showNormal();
  23. else
  24. showMaximized();
  25. return true;
  26. }
  27. }
  28. return false;
  29. }
To copy to clipboard, switch view to plain text mode 
Qt Code:
  1. CTitlebarWidget::CTitlebarWidget( QWidget* Parent ) :
  2. QFrame( Parent )
  3. {
  4. // Set the object name.
  5. setObjectName( "Titlebar" );
  6.  
  7. // Connect the dock signal when the floating state change.
  8. connect( Parent, SIGNAL( topLevelChanged( bool ) ), this, SLOT( ChangeFloatingState( bool ) ) );
  9.  
  10. // Create the title label.
  11. m_TitleLabel = new QLabel( Parent->windowTitle() );
  12. m_TitleLabel->setObjectName( "TitlebarLabel" );
  13.  
  14. // Minimize button.
  15. m_MinimizeButton = new QToolButton;
  16. m_MinimizeButton->setObjectName( "TitlebarMinimizeButton" );
  17. connect( m_MinimizeButton, SIGNAL( clicked() ), this, SLOT( MinimizeButton() ) );
  18.  
  19. // Maximize button.
  20. m_MaximizeButton = new QToolButton;
  21. m_MaximizeButton->setObjectName( "TitlebarMaximizeButton" );
  22. connect( m_MaximizeButton, SIGNAL( clicked() ), this, SLOT( ChangeParentMaximizeState() ) );
  23.  
  24. // Float button.
  25. m_FloatButton = new QToolButton;
  26. m_FloatButton->setObjectName( "TitlebarFloatButton" );
  27. connect( m_FloatButton, SIGNAL( clicked() ), this, SLOT( FloatButton() ) );
  28.  
  29. // Close button.
  30. m_CloseButton = new QToolButton;
  31. m_CloseButton->setObjectName( "TitlebarCloseButton" );
  32. connect( m_CloseButton, SIGNAL( clicked() ), Parent, SLOT( close() ) );
  33.  
  34. // Create the control layout.
  35. QHBoxLayout* ControlLayout = new QHBoxLayout;
  36. ControlLayout->setMargin( 0 );
  37. ControlLayout->setSpacing( 0 );
  38. ControlLayout->addWidget( m_MinimizeButton );
  39. ControlLayout->addWidget( m_MaximizeButton );
  40. ControlLayout->addWidget( m_FloatButton );
  41. ControlLayout->addWidget( m_CloseButton );
  42.  
  43. // Set the floating state.
  44. CDockWidget* ParentDock = static_cast< CDockWidget* >( Parent );
  45. ChangeFloatingState( ParentDock->isFloating() );
  46.  
  47. // Create the layout.
  48. QHBoxLayout* Layout = new QHBoxLayout;
  49. Layout->setMargin( 4 );
  50. Layout->addWidget( m_TitleLabel );
  51. Layout->addLayout( ControlLayout );
  52.  
  53. // Set the layout.
  54. setLayout( Layout );
  55. }
  56.  
  57. void CTitlebarWidget::SetTitle( const QString& Title )
  58. {
  59. m_TitleLabel->setText( Title );
  60. }
  61.  
  62. QString CTitlebarWidget::GetTitle() const
  63. {
  64. return m_TitleLabel->text();
  65. }
  66.  
  67. void CTitlebarWidget::mouseDoubleClickEvent( QMouseEvent* event )
  68. {
  69. ChangeParentMaximizeState();
  70. }
  71.  
  72. void CTitlebarWidget::mouseMoveEvent( QMouseEvent* event )
  73. {
  74. // Base class.
  75. QFrame::mouseMoveEvent( event );
  76.  
  77. // Check if we move with the left button.
  78. if( event->buttons() == Qt::MouseButton::LeftButton )
  79. {
  80. // Cast the parent.
  81. CDockWidget* Parent = static_cast< CDockWidget* >( parent() );
  82.  
  83. // Change parent state.
  84. if( Parent->isMaximized() )
  85. Parent->showNormal();
  86. }
  87. }
  88.  
  89. void CTitlebarWidget::MinimizeButton()
  90. {
  91. CDockWidget* Parent = static_cast< CDockWidget* >( parent() );
  92. Parent->setFloating( false );
  93. }
  94.  
  95. void CTitlebarWidget::FloatButton()
  96. {
  97. CDockWidget* Parent = static_cast< CDockWidget* >( parent() );
  98. Parent->setFloating( true );
  99. }
  100.  
  101. void CTitlebarWidget::ChangeParentMaximizeState()
  102. {
  103. // Cast the parent.
  104. CDockWidget* Parent = static_cast< CDockWidget* >( parent() );
  105.  
  106. // Change parent state.
  107. if( Parent->isMaximized() )
  108. Parent->showNormal();
  109. else
  110. Parent->showMaximized();
  111. }
  112.  
  113. void CTitlebarWidget::ChangeFloatingState( bool Floating )
  114. {
  115. if( Floating )
  116. {
  117. m_MinimizeButton->setVisible( true );
  118. m_MaximizeButton->setVisible( true );
  119. m_FloatButton->setVisible( false );
  120. }
  121. else
  122. {
  123. m_MinimizeButton->setVisible( false );
  124. m_MaximizeButton->setVisible( false );
  125. m_FloatButton->setVisible( true );
  126. }
  127. }
To copy to clipboard, switch view to plain text mode 
Is it a possible bug of Qt ?
Thanks