[Qt-interest] Iaaue with mouseGrabber

Mystical Rose mca.meraj at gmail.com
Mon Jul 25 22:07:08 CEST 2011


Hi All,

What about following code -

void MainWindow::hideWidget()
{
    do
    {
        ui->pushButton->grabMouse();

        QWidget *wgt =  qobject_cast<QPushButton*>(QWidget::mouseGrabber());
        if ( !wgt )
            break;

        QString str = wgt->objectName();

        ui->label->setText(str);
        ui->pushButton->releaseMouse();

    }while(false);

}



It should work without crash.
BTW grabMouse() has interesting documentation too.

Regards,
Meraj Ansari



On Mon, Jul 25, 2011 at 5:09 PM, Brad Hards <bradh at frogmouth.net> wrote:
> On Monday 25 July 2011 21:28:55 nandita-a.mehta at nokia.com wrote:
>> Hi
>> In my application i need to know which widget received the mouse click and
>> for that I am using mouseGrabber(). However the application crashes.
>>
>> To make it simple, in my Qt application I have a pushbutton; on its click a
>> slot (hideWidget) is triggered. In the slot, I am using mouseGrabber and
>> then finding the widget name. Can anyone explain why the app crashes?
> Probably because:
> If no widget in this application is currently grabbing the mouse, 0 is
> returned.
>
> Perhaps you're confusing mouse press and mouse click, or what grab means.
>
> Brad
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>



-- 
Meraj Ahmad Ansari
S/W Engineer
Aricent Technologies Limited
Gurgaon , India



More information about the Qt-interest-old mailing list