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. Why addMapping doesn't work?
Qt 6.11 is out! See what's new in the release blog

Why addMapping doesn't work?

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 4.9k Views 2 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.
  • V Offline
    V Offline
    Vladislav Lisovenko
    wrote on last edited by
    #1

    Hi.
    I have LineEditEx class inherited from QLineEdit. This class has property declared with this code:

    Q_PROPERTY(QString guid READ guid WRITE setGuid NOTIFY guidChanged)
    

    When I try to assing some value to guid in usual way everything works fine and:

    lineEditEx->guid="sdfsd";
    

    and then I can read assigned value:

    qDebug() << lineEditEx->getGuid();
    

    But when I try to add mapping my code doesn't work properly and I don't know why, this code works:

    mapper->addMapping(ui->lineEditEx, model->fieldIndex("_id"));
    

    but this code doesn't work:

    mapper->addMapping(ui->lineEditEx, model->fieldIndex("_id"), "guid");
    

    Where there's a will, there is a way.

    1 Reply Last reply
    0
    • Ni.SumiN Offline
      Ni.SumiN Offline
      Ni.Sumi
      wrote on last edited by Ni.Sumi
      #2

      Hi @Vladislav-Lisovenko ,

      QMap<QString, int> map;
      map->addMApping(string, int);

      It takes only key and value. only 2 parameters.

      But in your case mapper->addMapping(ui->lineEditEx, model->fieldIndex("_id"), "guid");
      It's 3 inside. So it won't accept.

      And from you code mapper->addMapping(ui->lineEditEx, model->fieldIndex("_id"), "guid");
      What will you get from the key ui->lineEdit?

      V 1 Reply Last reply
      0
      • Ni.SumiN Ni.Sumi

        Hi @Vladislav-Lisovenko ,

        QMap<QString, int> map;
        map->addMApping(string, int);

        It takes only key and value. only 2 parameters.

        But in your case mapper->addMapping(ui->lineEditEx, model->fieldIndex("_id"), "guid");
        It's 3 inside. So it won't accept.

        And from you code mapper->addMapping(ui->lineEditEx, model->fieldIndex("_id"), "guid");
        What will you get from the key ui->lineEdit?

        V Offline
        V Offline
        Vladislav Lisovenko
        wrote on last edited by Vladislav Lisovenko
        #3

        @Ni.Sumi http://doc.qt.io/qt-5/qdatawidgetmapper.html#addMapping-1
        I want to store some guid in lineEdit.

        Where there's a will, there is a way.

        1 Reply Last reply
        0
        • Ni.SumiN Offline
          Ni.SumiN Offline
          Ni.Sumi
          wrote on last edited by Ni.Sumi
          #4

          Hi @Vladislav-Lisovenko ,

          Sorry, I thought that you are using QMap , but yes addMapping is from QDatawidgetMapper .

          AFAIK, QLinedit widget has user proeprty by default. How can you give this "guid" to line Edit ? But you can send this "guid" to the widgets like QLabel.

          V 1 Reply Last reply
          0
          • Ni.SumiN Ni.Sumi

            Hi @Vladislav-Lisovenko ,

            Sorry, I thought that you are using QMap , but yes addMapping is from QDatawidgetMapper .

            AFAIK, QLinedit widget has user proeprty by default. How can you give this "guid" to line Edit ? But you can send this "guid" to the widgets like QLabel.

            V Offline
            V Offline
            Vladislav Lisovenko
            wrote on last edited by
            #5

            @Ni.Sumi I merely want to store hidden data, got from model, in lineEdit-widget.

            Where there's a will, there is a way.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              From your code, it doesn't seem that you have implemented the property properly.

              You seem to be using a variable named guid that you have deemed the getter in your Q_PROPERTY declaration thus getGuidisn't the getter.

              For variable names, I'd recommend using a prefix like _ to ensure there's no confusion.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              V 1 Reply Last reply
              0
              • SGaistS SGaist

                Hi,

                From your code, it doesn't seem that you have implemented the property properly.

                You seem to be using a variable named guid that you have deemed the getter in your Q_PROPERTY declaration thus getGuidisn't the getter.

                For variable names, I'd recommend using a prefix like _ to ensure there's no confusion.

                V Offline
                V Offline
                Vladislav Lisovenko
                wrote on last edited by Vladislav Lisovenko
                #7

                @SGaist Hi
                Getter for guid exists, but this code also doesn't work:

                Q_PROPERTY(QString guid READ getGuid WRITE setGuid NOTIFY guidChanged)
                

                Maybe I don't need Q_PROPERTY? But also when I comment line "Q_PROPERTY,,, " It doesn't work. I just need to map some hidden information to widget. I suppose problem not with Q_PROPERTY, problem with addMapping function.

                Where there's a will, there is a way.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Silly question but is ui->lineEditEx really a LineEditEx ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  V 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Silly question but is ui->lineEditEx really a LineEditEx ?

                    V Offline
                    V Offline
                    Vladislav Lisovenko
                    wrote on last edited by
                    #9

                    @SGaist Yes, of course ;). Code

                    ui->lineEdit-setGuid("sdfsdf");
                    qDebug() << ui->lineEdit-getGuid();
                    

                    works perfectly.

                    Where there's a will, there is a way.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Can you show how you setup your model and the mapper ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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