Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. For loop problem!
Forum Updated to NodeBB v4.3 + New Features

For loop problem!

Scheduled Pinned Locked Moved Solved Qt for Python
15 Posts 2 Posters 2.2k Views 1 Watching
  • 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.
  • jsulmJ jsulm

    @monamour If the first if is true you do return
    Also both if conditions are identical - what's the point?

    monamourM Offline
    monamourM Offline
    monamour
    wrote on last edited by
    #5

    @jsulm "The first if" should execute when the LINEDIT is blank. " The second if" will execute when the LINEDIT is NOT blank.

    jsulmJ 1 Reply Last reply
    0
    • monamourM monamour

      @jsulm "The first if" should execute when the LINEDIT is blank. " The second if" will execute when the LINEDIT is NOT blank.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #6

      @monamour Looks like you edited the code, because before both if were identical.
      Actually you can do it like this:

      if proc.name() not in x:
                      QMessageBox.information(self,"Error",'Blank!')
                      return
      
      else:
                      proc.kill()
                      QMessageBox.information(self, "Success", x2 +"has been terminated"
                      return
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      monamourM 1 Reply Last reply
      0
      • jsulmJ jsulm

        @monamour Looks like you edited the code, because before both if were identical.
        Actually you can do it like this:

        if proc.name() not in x:
                        QMessageBox.information(self,"Error",'Blank!')
                        return
        
        else:
                        proc.kill()
                        QMessageBox.information(self, "Success", x2 +"has been terminated"
                        return
        
        monamourM Offline
        monamourM Offline
        monamour
        wrote on last edited by monamour
        #7

        @jsulm Yes, I edited the code. It is same, not solved.

        jsulmJ 1 Reply Last reply
        0
        • monamourM monamour

          @jsulm Yes, I edited the code. It is same, not solved.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #8

          @monamour Did you check what x is and what proc.name is? Just print out both and see.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          monamourM 1 Reply Last reply
          0
          • jsulmJ jsulm

            @monamour Did you check what x is and what proc.name is? Just print out both and see.

            monamourM Offline
            monamourM Offline
            monamour
            wrote on last edited by
            #9

            @jsulm

            1- proc.name after "IF CONDITIONS"

            input

            print(x)
            print(proc.name())

            Output

            notepad.exe
            notepad.exe

            2-The full proc.name after "FOR LOOP"

            input

            print(proc.name())

            output

            System Idle Process
            System
            svchost.exe
            smss.exe
            csrss.exe
            MOM.exe
            wininit.exe
            csrss.exe
            services.exe
            lsass.exe
            lsm.exe
            python.exe
            explorer.exe
            svchost.exe
            svchost.exe
            chrome.exe
            WSHelper.exe
            cbInterface.exe
            taskhost.exe
            notepad.exe
            PresentationFontCache.exe
            SearchFilterHost.exe
            chrome.exe
            chrome.exe
            designer.exe
            thunderbird.exe
            fsnotifier64.exe
            conhost.exe
            chrome.exe
            svchost.exe
            notepad++.exe
            VSSVC.exe
            pycharm64.exe
            chrome.exe
            chrome.exe
            SearchProtocolHost.exe
            conhost.exe
            chrome.exe

            Process finished with exit code 0

            jsulmJ 1 Reply Last reply
            0
            • monamourM monamour

              @jsulm

              1- proc.name after "IF CONDITIONS"

              input

              print(x)
              print(proc.name())

              Output

              notepad.exe
              notepad.exe

              2-The full proc.name after "FOR LOOP"

              input

              print(proc.name())

              output

              System Idle Process
              System
              svchost.exe
              smss.exe
              csrss.exe
              MOM.exe
              wininit.exe
              csrss.exe
              services.exe
              lsass.exe
              lsm.exe
              python.exe
              explorer.exe
              svchost.exe
              svchost.exe
              chrome.exe
              WSHelper.exe
              cbInterface.exe
              taskhost.exe
              notepad.exe
              PresentationFontCache.exe
              SearchFilterHost.exe
              chrome.exe
              chrome.exe
              designer.exe
              thunderbird.exe
              fsnotifier64.exe
              conhost.exe
              chrome.exe
              svchost.exe
              notepad++.exe
              VSSVC.exe
              pycharm64.exe
              chrome.exe
              chrome.exe
              SearchProtocolHost.exe
              conhost.exe
              chrome.exe

              Process finished with exit code 0

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #10

              @monamour Maybe both strings use different encodings?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              monamourM 2 Replies Last reply
              0
              • jsulmJ jsulm

                @monamour Maybe both strings use different encodings?

                monamourM Offline
                monamourM Offline
                monamour
                wrote on last edited by
                #11

                @jsulm Means? because both of them are strings.

                jsulmJ 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @monamour Maybe both strings use different encodings?

                  monamourM Offline
                  monamourM Offline
                  monamour
                  wrote on last edited by
                  #12

                  @jsulm If I make two for loops, it will work. What is the common sense in this ?

                  1 Reply Last reply
                  0
                  • monamourM monamour

                    @jsulm Means? because both of them are strings.

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by jsulm
                    #13

                    @monamour said in For loop problem!:

                    Means? because both of them are strings

                    I mean different string encodings like Latin1, UTF-8, ...
                    Can you try to print out type(x) and type(proc.name())?
                    "If I make two for loops, it will work. What is the common sense in this ?" - I don't know what you mean.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    monamourM 2 Replies Last reply
                    0
                    • jsulmJ jsulm

                      @monamour said in For loop problem!:

                      Means? because both of them are strings

                      I mean different string encodings like Latin1, UTF-8, ...
                      Can you try to print out type(x) and type(proc.name())?
                      "If I make two for loops, it will work. What is the common sense in this ?" - I don't know what you mean.

                      monamourM Offline
                      monamourM Offline
                      monamour
                      wrote on last edited by monamour
                      #14
                      This post is deleted!
                      1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @monamour said in For loop problem!:

                        Means? because both of them are strings

                        I mean different string encodings like Latin1, UTF-8, ...
                        Can you try to print out type(x) and type(proc.name())?
                        "If I make two for loops, it will work. What is the common sense in this ?" - I don't know what you mean.

                        monamourM Offline
                        monamourM Offline
                        monamour
                        wrote on last edited by monamour
                        #15

                        @jsulm

                        for proc in psutil.process_iter():
                                    if proc.name()==x:
                                        proc.kill()
                                        QMessageBox.information(self, "Success", x2 +"has been terminated")
                                        return
                        
                         for proc in psutil.process_iter():
                                     if proc.name()!=x:
                                         QMessageBox.information(self, "Error","The process " +x2 + " is not found")
                                         return
                        
                        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