Results 1 to 7 of 7

Thread: QLineEdit - lostFocus signal problem

  1. #1
    Join Date
    Aug 2007
    Posts
    27
    Qt products
    Qt4
    Platforms
    Unix/X11

    Exclamation QLineEdit - lostFocus signal problem

    Hi guys.
    I don`t remember where, but I definitely found and example on the net for validating Input on a QLineEdit.

    My code is as follows:
    Qt Code:
    1. QRegExp regexp( "([a-zA-Z0-9]+:)*[a-zA-Z0-9]+" );
    2. QValidator *fileExtensionsValidator = new QRegExpValidator( regexp, this );
    3.  
    4. this->fileExtensionsToScan->setValidator( fileExtensionsValidator );
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void MainWindow::on_fileExtensionsToScan_lostFocus(){
    2. QString text = this->fileExtensionsToScan->text();
    3. int pos = 0;
    4. if ( this->fileExtensionsToScan->validator()->validate( text, pos ) != QValidator::Acceptable )
    5. text = text.left( text.size() - 1 );
    6.  
    7. this->fileExtensionsToScan->setText( text );
    8. }
    To copy to clipboard, switch view to plain text mode 

    Now... I`m using Fedora 7 with Qt4.3.1-3 installed with yum install qt4.

    I`ve been requested to make a build of my application based on a static qt lib build so I downloaded the sources file 'qt4-4.3.1-3.fc7.src.rpm', built the static lib with
    Qt Code:
    1. ./configure -static -nomake demos -nomake examples -nomake tools -release -qt-zlib -qt-gif -qt-libpng -qt-libmng -qt-libjpeg -no-opengl -no-qdbus -no-cups
    2. make
    3. make install
    To copy to clipboard, switch view to plain text mode 

    build Makefile with qmake on my project file(same .pro file I use for the shared library version of my application, only that the qmake I used was from the static build)

    then built my application.

    After I did the above, I keep getting:
    QMetaObject::connectSlotsByName: No matching signal for on_fileExtensionsToScan_lostFocus()
    Tried switching to the connect method but still:
    Object::connect: No such signal QLineEdit::lostFocus()
    Object::connect: (sender name: 'fileExtensionsToScan')
    Now... I see in present the documentation that no lostFocus() signal is defiend for QLineEdit but I think it was there in the recent earlier versions of 4.3.0 or 4.3.1.

    Why does it work perfectly on my 4.3.1-3.fc7 build of Qt and on my static built version of Qt it does not?

    Another problem I seem to have is that gif's file are not displayed although I used the above mentioned ./configure arguments.

    Please enlighten me on this issue or at least provide me an alternative to the validation without subclassing.

    Thank you guys.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QLineEdit - lostFocus signal problem

    QLineEdit::lostFocus() is part of Qt 3 support members. As the docs mention, you should use QLineEdit::editingFinished() instead.

    By the way, it should work when you turn Qt 3 support on:
    QT += qt3support
    J-P Nurmi

  3. #3
    Join Date
    Aug 2007
    Posts
    27
    Qt products
    Qt4
    Platforms
    Unix/X11

    Red face Re: QLineEdit - lostFocus signal problem

    Ooooo... orcourse!

    I had turned off qt3support Figured I didn't need it... guess i did after all :P

    And by the way... Qt4's approach on removing lostFocus() is quite uninspired if you ask me... This is why:
    void QLineEdit::editingFinished () [signal]
    This signal is emitted when the Return or Enter key is pressed or the line edit loses focus. Note that if there is a validator() or inputMask() set on the line edit and enter/return is pressed, the editingFinished() signal will only be emitted if the input follows the inputMask() and the validator() returns QValidator::Acceptable.
    Like... I have a validator set, right... and if the user inputs incorrect data, like "exe:txt:" this corrupts my data because no function was called to clean up the mess, why? Because editingFinished () did not get fired cause of Enter was not pressed or the input did not validate. Of course it did not validate!

    So, what to do in order to avoid qt3 support being compiled?

  4. #4
    Join Date
    Aug 2007
    Posts
    27
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QLineEdit - lostFocus signal problem

    Any news on how to check input, even if editingFinished() did not fire?

    I`m trying to understand the logic of this...

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QLineEdit - lostFocus signal problem

    You can always catch QEvent::FocusOut by either reimplementing QWidget::focusOutEvent() or installing an event filter.
    J-P Nurmi

  6. #6
    Join Date
    Aug 2007
    Posts
    27
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QLineEdit - lostFocus signal problem

    Thanks a lot, I managed to do it using an eventFilter

    Appreciate it jpn!

  7. #7
    Join Date
    Jun 2010
    Posts
    12
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QLineEdit - lostFocus signal problem

    Quote Originally Posted by Enygma View Post
    Any news on how to check input, even if editingFinished() did not fire?

    I`m trying to understand the logic of this...
    I know this is an old thread, but I was having problems with QLineEdit's editingFinished() signal and even found a bug mention of this that was never fixed on the official nokia bugreports forum. I have 3 line edits with QRegExpValidators on them, and a handler slot connected to their editingFinished() signal. The signal would sometimes not get fired when losing focus, at other times, I would have to move focus inside the dialog widget twice before two signals would be sent at once. I then found this thread and tried using the QT3 lostFocus() signal, which worked much more reliably in that the signal would fire as soon as a line edit lost focus, but it was still sending two signals at once.

    I'm not sure if it's really a bug or if I'm not handling it right, but I added this to the slot connected to editingFinished() in my QDialog reimplementation,

    Qt Code:
    1. if( receivedFocusOutSignalRecently /* a bool member set to false in the constructor */ )
    2. return;
    3. else {
    4. receivedFocusOutSignalRecently = true;
    5. QTimer::singleShot( 200, this, SLOT(resetReceivedFocusOutSignalRecently()) );
    6. }
    To copy to clipboard, switch view to plain text mode 

    and made a resetReceivedFocusOutSignalRecently() slot that changed the bool to false, and got away with not having to reimplement anything. Good luck and if anyone has more to offer about this please add your thoughts.

    EDIT: Also, it would be wonderful if, since they don't seem to like the lostFocus() signal, they would add an editingIncomplete() signal that fires when a line edit loses focus or the user presses enter or return with QValidator::Intermediate. The approach I took appears to be the only way to handle not leaving a line edit with unacceptable intermediate values with a validator on, which is a pretty big part of using validators in the first place. Maybe I'm missing something.
    Last edited by weevil; 17th June 2010 at 21:02.

Similar Threads

  1. Problem Euro Sign with QLineEdit
    By Kubil in forum Qt Programming
    Replies: 1
    Last Post: 24th August 2007, 04:56
  2. Problem emitting signal from a static function
    By Valheru in forum Qt Programming
    Replies: 21
    Last Post: 12th June 2007, 14:48
  3. Replies: 3
    Last Post: 15th April 2007, 19:16
  4. Problem with QLineEdit and setText
    By Elmo23x in forum Qt Programming
    Replies: 8
    Last Post: 12th April 2007, 12:35
  5. Signal problem in Qline Edit
    By awalesminfo in forum Newbie
    Replies: 1
    Last Post: 3rd April 2006, 09:13

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.