Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to have GUI based program wait until user enters acceptable input
Forum Updated to NodeBB v4.3 + New Features

How to have GUI based program wait until user enters acceptable input

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 641 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    poordev123
    wrote on last edited by poordev123
    #1

    I have a text edit in my gui that a user will enter a value into it. If the value is not entered, I want to show a popup message, tell them that it is empty, and then have them re-enter it. Right now what's happening is that the popup message is being displayed, but then the user does not have the chance to change the value, the program just continues running and crashes.

    I have a 'connect' push button which is the trigger for all of this that is called pb_ip_connection

    self.ui.pb_ip_connection.connect(self.get_ip)
    
    @staticmethod
    def get_ip():
        ip_addr = self.ui.text_edit_ip.toPlainText()
        if ip_addr == "":
            ctypes.windll.user32.MessageBoxW(0, "Enter an IP address", "ERROR", 1)
            # something has to go here to make the program go back and look for the new IP address that the user is going to enter before moving forward
    

    I am also aware that I can do something along the lines of

    while True: 
        ip_addr = self.ui.text_edit_ip.toPlainText()
        if ip_addr == "":
            ctypes.windll.user32.MessageBoxW(0, "Enter an IP address", "ERROR", 1 
            continue
        else:
            break
    

    That would work if the user was entering an input, but since this is gui driven it just shows the popup over and over again and does not give the user a chance to change anything

    JonBJ 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Use a QLineEdit instead a QTextEdit, connect to signal QLineEdit::textChanged() and check the input in the connected slot. Or/And put a QValidator on it so the user can not enter e.g. characters.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • P poordev123

        I have a text edit in my gui that a user will enter a value into it. If the value is not entered, I want to show a popup message, tell them that it is empty, and then have them re-enter it. Right now what's happening is that the popup message is being displayed, but then the user does not have the chance to change the value, the program just continues running and crashes.

        I have a 'connect' push button which is the trigger for all of this that is called pb_ip_connection

        self.ui.pb_ip_connection.connect(self.get_ip)
        
        @staticmethod
        def get_ip():
            ip_addr = self.ui.text_edit_ip.toPlainText()
            if ip_addr == "":
                ctypes.windll.user32.MessageBoxW(0, "Enter an IP address", "ERROR", 1)
                # something has to go here to make the program go back and look for the new IP address that the user is going to enter before moving forward
        

        I am also aware that I can do something along the lines of

        while True: 
            ip_addr = self.ui.text_edit_ip.toPlainText()
            if ip_addr == "":
                ctypes.windll.user32.MessageBoxW(0, "Enter an IP address", "ERROR", 1 
                continue
            else:
                break
        

        That would work if the user was entering an input, but since this is gui driven it just shows the popup over and over again and does not give the user a chance to change anything

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @poordev123
        As @Christian-Ehrlicher says, except that you may rather want to use signal QLineEdit::editingFinished().

        Completely separate from your question, it seems such a shame that you use ctypes.windll.user32.MessageBoxW() to display a message box. If you are going to use Qt why use anything like that? Anyway, QMessageBox Class.

        JoeCFDJ P 2 Replies Last reply
        4
        • JonBJ JonB

          @poordev123
          As @Christian-Ehrlicher says, except that you may rather want to use signal QLineEdit::editingFinished().

          Completely separate from your question, it seems such a shame that you use ctypes.windll.user32.MessageBoxW() to display a message box. If you are going to use Qt why use anything like that? Anyway, QMessageBox Class.

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by
          #4

          @JonB Jon has a good point. You code will not compile on Linux and MacOS. If your app is not developed for cross-platforms, Qt is not needed on Windows.

          1 Reply Last reply
          1
          • JonBJ JonB

            @poordev123
            As @Christian-Ehrlicher says, except that you may rather want to use signal QLineEdit::editingFinished().

            Completely separate from your question, it seems such a shame that you use ctypes.windll.user32.MessageBoxW() to display a message box. If you are going to use Qt why use anything like that? Anyway, QMessageBox Class.

            P Offline
            P Offline
            poordev123
            wrote on last edited by
            #5

            @JonB @JoeCFD Okay I just switched to using QMessageBox then, I had not thought about running this on different operating systems. Thank you for the tip.

            @Christian-Ehrlicher thank you for the textChanged input. I am going to try to implement that

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved