[solved] adding Qt to existing program
-
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.
-
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.
-
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.
-
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!
-
[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".
-
[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.