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. if else to switch case for GUI

if else to switch case for GUI

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 925 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.
  • A Offline
    A Offline
    Amine Djeddi
    wrote on last edited by
    #1

    hi my freinds i working on image processing project , works fine ... but i want to move to SWITH CASE insread of IF ELSE ...

    if (ui->medianbur->isChecked())
    { // program works fine ...
    }

    is this correct :
    switch () // no argument yet ...
    case : (ui->medianbur->isChecked())
    { // put the same program here....
    }

    jsulmJ 1 Reply Last reply
    0
    • A Amine Djeddi

      hi my freinds i working on image processing project , works fine ... but i want to move to SWITH CASE insread of IF ELSE ...

      if (ui->medianbur->isChecked())
      { // program works fine ...
      }

      is this correct :
      switch () // no argument yet ...
      case : (ui->medianbur->isChecked())
      { // put the same program here....
      }

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

      @Amine-Djeddi The syntax of your switch is wrong, but this is completely unrelated to Qt.
      One more thing: switch does not make sense when using with binary conditions. isChecked() returns a boolean, so you will have exactly 2 possibilities. Why do you want to use switch here? switch makes sense if you have many posibilities to check.

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

      1 Reply Last reply
      6
      • A Offline
        A Offline
        Amine Djeddi
        wrote on last edited by
        #3

        yes i have more than 2 possibilites like :

        if (ui->medianbur->isChecked())
        { // program works fine ...
        }
        if (ui->Grayscale->isChecked())
        { // program works fine ...
        }

        if (ui->cannymode->isChecked())
        { // program works fine ...
        }
        i want to convert this into switch case ,

        im blocked here :

        switch (ui->medianblur->isChecked())
        case true :
        {

        	// programme work fine 
        }
        
        JonBJ 1 Reply Last reply
        0
        • A Amine Djeddi

          yes i have more than 2 possibilites like :

          if (ui->medianbur->isChecked())
          { // program works fine ...
          }
          if (ui->Grayscale->isChecked())
          { // program works fine ...
          }

          if (ui->cannymode->isChecked())
          { // program works fine ...
          }
          i want to convert this into switch case ,

          im blocked here :

          switch (ui->medianblur->isChecked())
          case true :
          {

          	// programme work fine 
          }
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @Amine-Djeddi
          As @jsulm stated, it is pointless/unhelpful to use a switch against a condition which is boolean (values true or false). Use an if, possibly with an else. If necessary you can use:

          if (...)
              ...
          else if (...)
              ...
          else if (...)
              ...
          else
              ...
          

          Or, you can combine your conditions with && and ||s.

          There is nothing about what you have shown which would benefit from a switch().

          1 Reply Last reply
          6
          • A Offline
            A Offline
            Amine Djeddi
            wrote on last edited by
            #5

            ok i got it , thank you @jsulm and @JonB for make things clear

            1 Reply Last reply
            1

            • Login

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