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. QLineEdit lostFocus problem
Forum Updated to NodeBB v4.3 + New Features

QLineEdit lostFocus problem

Scheduled Pinned Locked Moved Solved General and Desktop
25 Posts 5 Posters 3.6k Views 4 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.
  • EddyE Eddy

    You cannot put a line without putting something behind MOBILITY
    like
    MOBILITY += sensors
    What is it you want to do here?

    I recommend when looking at your code to make it work first on desktop before even thinking on using it on Android.
    Comment that line for now and look in Qt Creator at all the lines with errors. Solve one at a time...you cannot let lines open or ignore warnings from the compiler.

    TheCipo76T Offline
    TheCipo76T Offline
    TheCipo76
    wrote on last edited by TheCipo76
    #16

    @eddy I've started to load it to my smartphone (Android) then i've decided to try before on my mac..

    i haven't put this lines:

    CONFIG += mobility
    MOBILITY =
    

    in the pro file..

    now i've comment it with #

    the only errors i can see is in Compile Output:

    duplicate symbol _Target in:
    fresatura.o
    mainwindow.o
    duplicate symbol _Target in:
    fresatura.o
    moc_fresatura.o
    ld: 2 duplicate symbols for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make: *** [CNCMaster.app/Contents/MacOS/CNCMaster] Error 1
    15:10:04: The process "/usr/bin/make" exited with code 2.
    Error while building/deploying project CNCMaster (kit: Desktop Qt 5.13.0 clang 64bit)
    When executing step "Make"
    15:10:04: Elapsed time: 00:03.

    i've searched in the project but i can't find duplicate

    Pl45m4P 1 Reply Last reply
    0
    • TheCipo76T TheCipo76

      @eddy I've started to load it to my smartphone (Android) then i've decided to try before on my mac..

      i haven't put this lines:

      CONFIG += mobility
      MOBILITY =
      

      in the pro file..

      now i've comment it with #

      the only errors i can see is in Compile Output:

      duplicate symbol _Target in:
      fresatura.o
      mainwindow.o
      duplicate symbol _Target in:
      fresatura.o
      moc_fresatura.o
      ld: 2 duplicate symbols for architecture x86_64
      clang: error: linker command failed with exit code 1 (use -v to see invocation)
      make: *** [CNCMaster.app/Contents/MacOS/CNCMaster] Error 1
      15:10:04: The process "/usr/bin/make" exited with code 2.
      Error while building/deploying project CNCMaster (kit: Desktop Qt 5.13.0 clang 64bit)
      When executing step "Make"
      15:10:04: Elapsed time: 00:03.

      i've searched in the project but i can't find duplicate

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #17

      @thecipo76

      It may cause trouble, because you define two QObject - derived classes in one header file. Put your custom LineEdit in a separate headerfile (and .cpp) and include it in your dialog. Then try to compile it again :)


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      TheCipo76T 1 Reply Last reply
      3
      • Pl45m4P Pl45m4

        @thecipo76

        It may cause trouble, because you define two QObject - derived classes in one header file. Put your custom LineEdit in a separate headerfile (and .cpp) and include it in your dialog. Then try to compile it again :)

        TheCipo76T Offline
        TheCipo76T Offline
        TheCipo76
        wrote on last edited by
        #18

        @pl45m4
        i've definded it in a separate file

        mylineedit.h

        #ifndef MYLINEEDIT_H
        #define MYLINEEDIT_H
        
        #include <QApplication>
        #include <QLineEdit>
        
        extern QString Target;
        
        class MyLineEdit : public QLineEdit
        {
            Q_OBJECT
        public:
            MyLineEdit(QWidget *parent = nullptr) : QLineEdit(parent){}
        protected:
            void focusOutEvent(QFocusEvent *event)
            {
               QLineEdit::focusOutEvent(event);
               QWidget * widgetName = qApp->focusWidget();
               Target = widgetName->objectName();
        
                if(!hasAcceptableInput())
                {
                    setFocus();
                }
        
            }
        signals:
        };
        
        #endif // MYLINEEDIT_H
        
        

        and i've #included it in fresatura.cpp

        #include "mylineedit.h"
        

        but no way..

        Undefined symbols for architecture x86_64:
        "_Target", referenced from:
        MyLineEdit::focusOutEvent(QFocusEvent*) in moc_mylineedit.o
        ld: symbol(s) not found for architecture x86_64
        clang: error: linker command failed with exit code 1 (use -v to see invocation)
        make: *** [CNCMaster.app/Contents/MacOS/CNCMaster] Error 1
        15:32:58: The process "/usr/bin/make" exited with code 2.
        Error while building/deploying project CNCMaster (kit: Desktop Qt 5.13.0 clang 64bit)
        When executing step "Make"
        15:32:58: Elapsed time: 00:02.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #19

          @thecipo76 said in QLineEdit lostFocus problem:
          extern QString Target;

          and then in the mylineedit.CPP file you also have

          QString Target;

          so its actually defined ?

          TheCipo76T 1 Reply Last reply
          3
          • mrjjM mrjj

            @thecipo76 said in QLineEdit lostFocus problem:
            extern QString Target;

            and then in the mylineedit.CPP file you also have

            QString Target;

            so its actually defined ?

            TheCipo76T Offline
            TheCipo76T Offline
            TheCipo76
            wrote on last edited by
            #20

            @mrjj ok i've defined it in .cpp file and works..
            but i've lost Target value

            1 Reply Last reply
            1
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #21

              Hi
              Can you explain the original issue ?
              If you click on lineEdit , then click on keyboard, then
              lineedit loose its focus ?

              TheCipo76T 1 Reply Last reply
              0
              • mrjjM mrjj

                Hi
                Can you explain the original issue ?
                If you click on lineEdit , then click on keyboard, then
                lineedit loose its focus ?

                TheCipo76T Offline
                TheCipo76T Offline
                TheCipo76
                wrote on last edited by
                #22

                @mrjj No, if i click on "1" pushbutton i have to read Target in order to know in wich mylineedit i have to insert "1".

                Target is the mylineedit who lost focus

                i don't know if it's clear

                mrjjM 1 Reply Last reply
                0
                • TheCipo76T TheCipo76

                  @mrjj No, if i click on "1" pushbutton i have to read Target in order to know in wich mylineedit i have to insert "1".

                  Target is the mylineedit who lost focus

                  i don't know if it's clear

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #23

                  @thecipo76
                  well first of all the buttons should have NoFocus set so clicking them do not steal focus.
                  There is no reason for it to lose focus unless you pop something else up first that takes focus.
                  But in your case, its not keyboard that steal it but something else
                  that takes focus while in the window ??

                  TheCipo76T 1 Reply Last reply
                  5
                  • mrjjM mrjj

                    @thecipo76
                    well first of all the buttons should have NoFocus set so clicking them do not steal focus.
                    There is no reason for it to lose focus unless you pop something else up first that takes focus.
                    But in your case, its not keyboard that steal it but something else
                    that takes focus while in the window ??

                    TheCipo76T Offline
                    TheCipo76T Offline
                    TheCipo76
                    wrote on last edited by TheCipo76
                    #24

                    @mrjj Ah.. with NoFocus setted i don't need to subclass QLineEdit
                    and it's all more easy

                    Thank you very much

                    mrjjM 1 Reply Last reply
                    1
                    • TheCipo76T TheCipo76

                      @mrjj Ah.. with NoFocus setted i don't need to subclass QLineEdit
                      and it's all more easy

                      Thank you very much

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #25

                      @thecipo76
                      Yep it helps a lot. :)
                      I used qApp->focusWidget(); and sendEvent (key down / key up ) to post the keys to any widget that has keyboard focus and it works pretty well.

                      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