Results 1 to 4 of 4

Thread: QMessageBox and Focus

  1. #1
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default QMessageBox and Focus

    Hi, I've problem with an application...the code is something like this one:

    class MyDialog: public QDialog
    {
    <......other code.......>
    public slots:
    void angleChanged();
    private:
    QLineEdit leAngle;

    }

    MyDialog::MyDialog()
    {
    <......other code.......>
    connect(angle, SIGNAL(editingFinished ()), this, SLOT(angleChanged()));
    }

    void MyDialog::angleChanged()
    {
    <......other code.......>
    double angle = leAngle.text().toDouble();
    if (angle<45)
    QMessageBox::Warning(this, "Warning", "Angle less than 45°");
    double x = sin(angle);
    <......other code.......>
    }

    When I open one instance of MyDialog, change the leAngle with a string like "30" and when this one lost the focus the QMessageBox Dialog appear 2 times, double x = sin(angle) is exectued only the second time that the QMessageBox is called ....Obviously I don't want this strange behaviour.
    I investigate and this behaviour is due to the fact that when the QMessageBox is called for the first time the MyDialog lost the focus and so angleChanged is called another time and so QMessageBox too.
    How can I resolve this question without remove the connection with the signal editingFinished?

    What the meaning of the QWidget::setFocusProxy function?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QMessageBox and Focus

    did you specify parent for leAngle? why don't create leAngle on a heap?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QMessageBox and Focus

    This is an semplified example...don't worry, the leAngle is created in the heap in my real code and has a parent!
    I think that the problem it isn't realated to this factor!

  4. #4
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QMessageBox and Focus

    Solved...I don't know if it's the best solution but work.
    Before calling a QMessageBox I disconnet every editingFinished signal and just after I re-connect this ones.

Similar Threads

  1. QTableView focus issue
    By gemidjy in forum Qt Programming
    Replies: 4
    Last Post: 19th February 2008, 15:51
  2. default on focus different item in messagebox?
    By gfunk in forum Qt Programming
    Replies: 1
    Last Post: 26th October 2007, 05:54

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.