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. Accessing d pointer d_func from QLineEdit class
QtWS25 Last Chance

Accessing d pointer d_func from QLineEdit class

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 878 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.
  • T Offline
    T Offline
    TomQue
    wrote on last edited by
    #1

    I am trying to access the d pointer but the error that d_func is private for QLineEdit. I am having a hard time accessing it here is the code

    Q_D(QLineEdit);//<= this is where the error of that d is a private of QLineEdit
    if (d->control->isReadOnly()) {
    e->ignore();
    return;
    }

    JKSHJ 1 Reply Last reply
    0
    • T TomQue

      I am trying to access the d pointer but the error that d_func is private for QLineEdit. I am having a hard time accessing it here is the code

      Q_D(QLineEdit);//<= this is where the error of that d is a private of QLineEdit
      if (d->control->isReadOnly()) {
      e->ignore();
      return;
      }

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @TomQue said in Accessing d pointer d_func from QLineEdit class:

      I am trying to access the d pointer

      What is your goal?

      It is private, we are not supposed to access it.

      if (d->control->isReadOnly())

      Call the public function instead: if (this->isReadOnly())

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      2
      • T Offline
        T Offline
        TomQue
        wrote on last edited by
        #3

        I am trying to re-implement a function in QLineEdit so I change its behaviour and it requires I access the d pointer.

        JKSHJ 1 Reply Last reply
        0
        • T TomQue

          I am trying to re-implement a function in QLineEdit so I change its behaviour and it requires I access the d pointer.

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          @TomQue said in Accessing d pointer d_func from QLineEdit class:

          I am trying to re-implement a function in QLineEdit so I change its behaviour

          Please describe the changed behaviour that you want to implement

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • T Offline
            T Offline
            TomQue
            wrote on last edited by
            #5

            It pertains to passwordEchoOnEdit. its the only mode that deletes the contents once you switch echo modes. The original code that of QLineEdit re-implements the function InputmethodEvent and forces it to clear. I am trying re-implement it using my own version of the function so it doesnt clear

            here is the original code
            Q_D(QLineEdit);//<= this is where the error of that d is a private of QLineEdit
            if (d->control->isReadOnly()) {
            e->ignore();
            return;
            }
            if (echoMode() == PasswordEchoOnEdit && !d->control->passwordEchoEditing()) {
            // Clear the edit and reset to normal echo mode while entering input
            // method data; the echo mode switches back when the edit loses focus.
            // ### changes a public property, resets current content.
            d->updatePasswordEchoEditing(true);
            clear();//<= this is where it clears the password
            }
            }

            For to go through I need to access the d pointer

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

              You have to install and use the private headers. But then there is no BC guarantee on this usage anymore. It may not work anymore with a new Qt version (or an older).

              What exactly do you need from the d-pointer? QWidget::inputMethodEvent() is virtual so simply override it and call the base class (or not depending on your needs).

              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
              2
              • T Offline
                T Offline
                TomQue
                wrote on last edited by TomQue
                #7

                I need to access its members. like this one updatePasswordEchoEditing(true);

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

                  As I said - you need to install the private headers and use them. And you need to recompile your program everytime Qt gets updated since private headers are subject to change every time.

                  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
                  0
                  • nageshN Offline
                    nageshN Offline
                    nagesh
                    wrote on last edited by
                    #9

                    @TomQue said in Accessing d pointer d_func from QLineEdit class:

                    The original code that of QLineEdit re-implements the function InputmethodEvent and forces it to clear. I am trying re-implement it using my own version of the function so it doesnt clear

                    My simplest solution for the modified behavior (not to clear the text content) of "PasswordEchoOnEdit" will be as follows.

                    1)set the lineEdit "passwdEdit" echomode as "normal"
                    2)connect the QApplication focusChanged signal to lambda function
                    3)In lambda function check
                    if last focus widget was "passwdEdit" then set echommode as "Password"
                    else if Current focus is "passwdEdit" then set echommode as "Normal"

                    tested code sample is as follows

                    connect(qApp, &QApplication::focusChanged, [this](QWidget *oldFocus, QWidget *newFocus )
                        {
                            if(oldFocus == this->ui->passwdEdit)
                               this->ui->passwdEdit->setEchoMode(QLineEdit::Password);
                            else if(newFocus ==this->ui->passwdEdit)  
                                this->ui->passwdEdit->setEchoMode(QLineEdit::Normal);
                        }   );
                    
                    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