Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. German
  4. template Funktion setFocusHelp
Qt 6.11 is out! See what's new in the release blog

template Funktion setFocusHelp

Scheduled Pinned Locked Moved Solved German
2 Posts 1 Posters 1.4k 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.
  • G Offline
    G Offline
    Galilio
    wrote on last edited by
    #1

    Hallo zusammen,

    ich wollte eine Template Funktion schreiben, die mir der Focus ja nach State (Status der Anwendung) entwieder auf PushButton oder QLineEdit setzen.

    Die Funktion sieht so aus:

    template <typename T>
    	void setFocusEncoderTest(T a)
    {
           if(a  == ui.lineEditBenutzerName)
           {
               ui.lineEditbenutzerName->setFocus(Qt::OtherFocusReason);
           }
          if(a == ui.pushNameValidation)
           {
                ui.pushNameValidation->setFocus();
           }
            .........
    }
    

    Hier ist der Aufruf:

     setFocusEncoderTest (ui.lineEditBenutzerName)
    

    Das funktioniert aber nicht.
    Fehler :

    error C2446: '==': no conversion from 'QPushButton *' to 'QLineEdit *'
    

    Ich dachte template Funktion ist für so was gedacht oder lag ich falsch
    Danke

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Galilio
      wrote on last edited by
      #2

      Mit template wird das nicht gehen aber wenn ich so schreibe :

         void setFocusEncoderTest(QWidget* a)
      {
             if(a  == ui.lineEditBenutzerName)
             {
                 ui.lineEditbenutzerName->setFocus(Qt::OtherFocusReason);
             }
            if(a == ui.pushNameValidation)
             {
                  ui.pushNameValidation->setFocus();
             }
              .........
      }
      

      oder so :(Funktionsüberladen)

      void setFocusEncoderTest(QPushButton* a) {
          a->setFocus();
      }
       
      void setFocusEncoderTest(QLineEdit* a) {
          a->setFocus(Qt::OtherFocusReason);
      }
      
      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