Results 1 to 6 of 6

Thread: QLineEdit will not change with QFileDialog (pyqt)

  1. #1
    Join Date
    Sep 2009
    Posts
    7
    Thanks
    3
    Qt products
    Platforms
    Unix/X11 Windows

    Default QLineEdit will not change with QFileDialog (pyqt)

    Some odd QLineEdit behavior... I want a QLineEdit to display the file path to an SQLite3 database.

    txtdb is a QLineEdit

    This changes the text perfectly:
    Qt Code:
    1. txtdb.setText("foo")
    To copy to clipboard, switch view to plain text mode 


    This prints the filename as a string as expected:
    Qt Code:
    1. def getdb():
    2. return QtGui.QFileDialog.getOpenFileName(None, "Select your database file", "", "SQLite 3 Databases (*.sq3)")
    3.  
    4. print getdb()
    To copy to clipboard, switch view to plain text mode 


    Put them together...
    Qt Code:
    1. txtdb.setText(getdb())
    To copy to clipboard, switch view to plain text mode 
    ..and the text just does not change! Even
    Qt Code:
    1. a=getdb()
    2. txtdb.setText(a)
    To copy to clipboard, switch view to plain text mode 
    is a total fail!

    Anyone got any ideas how to fix this?

    Rich

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QLineEdit will not change with QFileDialog (pyqt)

    What is the type of "a" and what is the content of "a" in the last code snippet? Are you able to print a?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2009
    Posts
    7
    Thanks
    3
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit will not change with QFileDialog (pyqt)

    Hi,

    Thanks for the reply.

    Here's the most annoying thing: "print a" prints the file path perfectly! It just will not change the QLineEdit! I can't even think of a workaround.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QLineEdit will not change with QFileDialog (pyqt)

    But what is its type? It's probably not "QString instance", is it?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    Richie (6th September 2009)

  6. #5
    Join Date
    Sep 2009
    Posts
    7
    Thanks
    3
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit will not change with QFileDialog (pyqt)

    >>>> print type(a)
    <class 'PyQt4.QtCore.QString'>

    It was generated by QFileDialog::getOpenFileName, which returns a QString.

    I'm stumped.
    Last edited by Richie; 6th September 2009 at 16:29. Reason: spelling error

  7. #6
    Join Date
    Sep 2009
    Posts
    7
    Thanks
    3
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit will not change with QFileDialog (pyqt)

    Solved! If I explicitly set it to a QString, it works perferctly.

    Qt Code:
    1. a=QtCore.QString(getdb())
    2. txtdb.setText(a)
    To copy to clipboard, switch view to plain text mode 

    wysota, you're a hero. Many thanks!

Similar Threads

  1. Change QLabel to QLineEdit when mousePressEvent happens
    By naoyamakino in forum Qt Programming
    Replies: 2
    Last Post: 16th July 2009, 18:37
  2. Replies: 5
    Last Post: 10th July 2009, 12:11
  3. Pointer Question related to QLineEdit
    By ChrisReath in forum Qt Programming
    Replies: 1
    Last Post: 23rd May 2008, 15:13
  4. QValidator, regular expressions and QLineEdit
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 8th August 2007, 01:25

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.