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. [Solved] moc, setProperty
Forum Updated to NodeBB v4.3 + New Features

[Solved] moc, setProperty

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.3k Views 1 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.
  • P Offline
    P Offline
    paul_peter
    wrote on last edited by
    #1

    Hi there,

    i have a short question concerning the setProperty member of an widget.
    In a slot i receive changes in a combobox which has the dynamic property "relatedProperty" set to a property of another widget like "orientation" for example.
    The slot procedure extracts the dynamic property. This is used for setting a widgets property depending on the "relatedProperty" value of the combobox and the value of the combobox itself. To achive this behaviour i tried the following c++ code.

    @
    char property = sender()->property("relatedProperty").toChar().toAscii();
    qDebug() << tempModule.widget->setProperty(&property, Value);
    @

    But i only get "false" as output for the last qDebug() line.
    I spent a lot of time solving this but i can't find a solution.
    I hope someone has good ideas to fixthis problem.

    cheers paul

    1 Reply Last reply
    0
    • L Offline
      L Offline
      luisvaldes88
      wrote on last edited by
      #2

      I think I understand what you want and I try to make a solution.

      You can try this code:

      @QString relatedProperty(sender()->relatedProperty->property("relatedProperty").toString());
      char *property = new char[relatedProperty.toStdString().size() + 1];
      strcpy(property, relatedProperty.toStdString().c_str());
      ui->plainTextEdit->setProperty(property, Value);
      delete [] property;@

      Simpler version:

      @ui->plainTextEdit->setProperty(sender()->relatedProperty->property("relatedProperty").toString().toStdString().c_str(), Value);@

      Tell me if it worked, or if it is not what you need, explain better and we will make it work.

      Muchos quieren, pocos pueden, algunos consiguen.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lgeyer
        wrote on last edited by
        #3

        toChar() returns the QVariant as QChar, a single character. This is most probably not what you've meant, because "orientation" usually does not fit into a single character. Use toString() instead.

        @
        QObject objectA;
        objectA.setProperty("relatedProperty", QString("orientation"));

        ...

        QByteArray relatedProperty = objectA.property("relatedProperty").toString().toLatin1();

        QObject objectB;
        objectB.setProperty(relatedProperty.constData(), ...);
        @
        On a sidenote: do not use toAscii(); it is deprecated and will be no longer available in Qt5.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          paul_peter
          wrote on last edited by
          #4

          thank you very mouch for your help
          @
          ui->plainTextEdit->setProperty(sender()->property("relatedProperty").toString().toStdString().c_str(), Value);
          @
          works like a charm!

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            You are welcome. Feel free to edit the thread title to '[Solved] ...' to indicate that there is a solution inside.

            And bear in mind that there is a significat performance penalty in using <code>.toStdString().c_str()</code> over <code>.toLatin1().constData()</code>.

            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