Results 1 to 7 of 7

Thread: While loop problem in pyqt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2007
    Posts
    10
    Thanks
    1

    Default While loop problem in pyqt

    I am new here, so I hope it is not a wrong place to ask for pyqt.

    I wrote a while loop in pyqt but I want it to stop to take input from user.I do this in python with raw_input but it doesn't work in pyqt.How can I do this in pyqt.

    Qt Code:
    1. cev = str(ui.lineEdit.text()).lower()
    2.  
    3. guess = 0
    4. f = 0
    5.  
    6. while cev != answer:
    7. guess += 1
    8.  
    9. ui.label_6.setText(QtGui.QApplication.translate("MainWindow", "Wrong answer!", None, QtGui.QApplication.UnicodeUTF8))
    10.  
    11. f += 1
    12.  
    13. ui.label_4.setText(answer[0:f])
    14.  
    15. if answer[0:f] == answer[0:]:
    16. ui.label_4.setText(answer[0:f])
    17. ui.label_6.setText(QtGui.QApplication.translate("MainWindow"," Answer is revealed", None, QtGui.QApplication.UnicodeUTF8))
    18.  
    19. ui.label_9.setText(QtGui.QApplication.translate("MainWindow", soz[sor1], None, QtGui.QApplication.UnicodeUTF8))
    20. liste.pop(s)
    21. return self.sor()
    22. HERE ?
    23. "cev = raw_input("..................:")"
    To copy to clipboard, switch view to plain text mode 

    I need a code here to take input from user like "raw_input"
    Last edited by neverlander; 16th December 2007 at 15:46.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: While loop problem in pyqt

    Where should that input come from? Do you want to retrieve the text that user has entered into some widget?

    In general it is a bad idea to have long loop in event-based application.

  3. #3
    Join Date
    Nov 2007
    Posts
    10
    Thanks
    1

    Default Re: While loop problem in pyqt

    It is not a long loop.I revised the codes above.I ask a word to the user.If he makes a mistake the first letter of the answer reveals.But here because ı couldnot take another input from user the loop continues and reveals all the letters.I want it to reveal the letters one by one after the user enters his answer.

    I take the input from user by line edit.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: While loop problem in pyqt

    Quote Originally Posted by neverlander View Post
    I take the input from user by line edit.
    In that case you have to connect to the QLineEdit::textChanged() or some other QLineEdit signal and get rid of that loop.

  5. #5
    Join Date
    Nov 2007
    Posts
    10
    Thanks
    1

    Default Re: While loop problem in pyqt

    I am not so good at pyqt.Can you give me an example on how to use it?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: While loop problem in pyqt

    See this: http://zetcode.com/tutorials/pyqt4/widgets. It shows the typical way of doing things in Qt. In the Checkbox example you have a changeTitle() slot that is invoked every time the user clicks the check box. You don't need any loops to read data from the user -- the data will be delivered to you.

    If you make a loop in your application, the event loop inside Qt won't run and Qt won't be able to redraw widgets and receive input from the user. So basically your application should only react to signals and events, instead of enforcing the program flow. Of course you can have loops in your code, but they should be short or the application will become unresponsive*.

    The whole tutorial is here: http://zetcode.com/tutorials/pyqt4/


    * You can use QCoreApplication::processEvents() to avoid this, but you should do that only as the last resort.

  7. #7
    Join Date
    Nov 2007
    Posts
    10
    Thanks
    1

    Default Re: While loop problem in pyqt

    Thank you very much...

Similar Threads

  1. Workload in a QThread blocks main application's event loop ?
    By 0xBulbizarre in forum Qt Programming
    Replies: 14
    Last Post: 9th April 2006, 21:55
  2. Replies: 16
    Last Post: 7th March 2006, 15:57
  3. While statement inside the main loop
    By OnionRingOfDoom in forum Qt Programming
    Replies: 4
    Last Post: 8th February 2006, 18:17

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
  •  
Qt is a trademark of The Qt Company.