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] adding Qt to existing program
Forum Updated to NodeBB v4.3 + New Features

[solved] adding Qt to existing program

Scheduled Pinned Locked Moved General and Desktop
45 Posts 6 Posters 22.6k 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.
  • Z Offline
    Z Offline
    ZapB
    wrote on last edited by
    #36

    Which values are you trying to have displayed and what are their types? If you are emitting a single double then the signal, slot and connect are fine.

    If you want to display 2 doubles then you need to modify:

    • The dataChanged() signal to have two double arguments ie

    @void dataChanged( double val1, double val2 );@

    • The Widget::setValue() function to accept a corresponding pair of doubles:

    @void setValue( double val1, double val2 );@

    • The connect to use the new signal/slot signatures:

    @connect (soc, SIGNAL(dataChanged(double,double)), this, SLOT(setValue(double,double)));@

    Then finally you actually need to emit your signal from your calculation function.

    If instead you are using int's then simply replace double for int in the above.

    Nokia Certified Qt Specialist
    Interested in hearing about Qt related work

    1 Reply Last reply
    0
    • mzimmersM Offline
      mzimmersM Offline
      mzimmers
      wrote on last edited by
      #37

      Thanks for the explanation, Gerolf...that does help.

      Zap: I wish to display two ints. I understand now that I have to replace the doubles with ints. Now that I'm displaying two variables (ints), what is the syntax for forming the output string? I tried this:
      @ QString s = QString("shaperOutI is %1. shaperOutQ is %2.").arg(shaperOutI, shaperOutQ);
      @
      But that gives no output at all. Do I need two separate strings? What if I wanted the output on separate lines?

      Thanks. I'll have some more questions when I finish waking up.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #38

        use this:

        @
        QString s = QString("shaperOutI is %1. shaperOutQ is %2.").arg(shaperOutI).arg(shaperOutQ);
        @

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          ZapB
          wrote on last edited by
          #39

          Gerolf has already shown you how to format the string. If you want it split over two lines then you need to include a "\n" in your string:

          @QString s = QString("shaperOutI is %1.\nshaperOutQ is %2.").arg(shaperOutI).arg(shaperOutQ);@

          You may need to set the wordWrap property of the QLabel to true too - I can't recall offhand.

          Nokia Certified Qt Specialist
          Interested in hearing about Qt related work

          1 Reply Last reply
          0
          • mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #40

            Oh, this is OUTSTANDING. Thanks so much to everyone for their help in this thread. It may not seem like much to anyone else, but this is a major step forward for me.

            A final question about all this: can someone explain this line:

            @QString s = QString("shaperOutI is %1. shaperOutQ is 2.").arg(shaperOutI).arg(shaperOutQ);@

            What's going on with the consecutive .arg calls?

            I've got a ton of other questions now, but they're not apropos of this particular thread, so...I'll bundle them into a new thread. This one, I think we can mark solved (except I don't remember how to do that).

            Thanks again!

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #41

              a qstring object has a method called arg which replaces %1 by its value and returns a temporary object. if on this temp object, another arg is called, it replaces all instances of %2 by its value and so on. Afaik, up to 99 :-)

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • mzimmersM Offline
                mzimmersM Offline
                mzimmers
                wrote on last edited by
                #42

                Interesting...thanks.

                So...how do I mark this solved? With a tag?

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  giesbert
                  wrote on last edited by
                  #43

                  go to your first post, click edit and change the title :-)
                  Just add [Solved] in front

                  Nokia Certified Qt Specialist.
                  Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #44

                    [quote author="Gerolf" date="1301503305"]a qstring object has a method called arg which replaces %1 by its value and returns a temporary object. if on this temp object, another arg is called, it replaces all instances of %2 by its value and so on. Afaik, up to 99 :-)[/quote]

                    The rationale behind the %1 %2 and so on is, that these strings are regularly translatable and the placeholders need not be integers or numbers but also strings. In some languages, things must be reordered to result in a valid sentence. So you can the write

                    @
                    QString x = QString("%2 is before %1).arg("first").arg("second");
                    @

                    The resulting string is "second is before first".

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • Z Offline
                      Z Offline
                      ZapB
                      wrote on last edited by
                      #45

                      [quote author="mzimmers" date="1301501568"]Oh, this is OUTSTANDING. Thanks so much to everyone for their help in this thread. It may not seem like much to anyone else, but this is a major step forward for me.[/quote]

                      You're welcome. The initial steps are often the most confusing with a new technology. I will shortly post a modified example that performs the calculations in a separate thread and uses signals to let the main GUI thread know about the current status. That way you;ll have an example on which you can build if you do need to do some seriously time consuming number crunching without blocking the GUI.

                      Nokia Certified Qt Specialist
                      Interested in hearing about Qt related work

                      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