OK, I don't know if this is Off-Topic for the group(s), because "QT" isn't "Pure C++", and Slackware is a distro, but those guys are sharp. :-) And I've crossposted to sci.electroncs.design because I can. ;-P
Anyways, I want to crow about what I've done. I've been dabbling, kind of poking away at the QT tutorials, but when I get to the "Now, write some C++ to make it all go", I kinda hit a railroad crossing. ;-) So, I downloaded "Thinking in C++", and actually printed it on dead tree paper, and took it to bed with me to read myself to sleep. ;-) (it's about 4" thick, overall, printed single-sided on 20# letter-size. ;-) ) I really like the way that they mention, "Answers to the exercises are available for a nominal fee..."
So, anyways, I'm sitting here, kind of bored because there's no work and it really only takes a couple of hours to catch up on a day's worth of internet, and something bit me behind the knees, and I hauled out the ol' QT tutorial again, and popped up TICPPV1.pdf on another window, and in about an hour I'd produced:
But it's different from what came in the QT tutorial:
------------------------------------ void ConversionForm::convert() { enum MetricUnits { Kilometers, Meters, Centimeters, Millimeters }; enum OldUnits { Miles, Yards, Feet, Inches };
// Retrieve the input double input = numberLineEdit->text().toDouble(); double scaledInput = input;
// internally convert the input to millimeters switch ( fromComboBox->currentItem() ) { case Kilometers: scaledInput *= 1000000; break; case Meters: scaledInput *= 1000; break; case Centimeters: scaledInput *= 10; break; }
//convert to inches double result = scaledInput * 0.0393701;
switch ( toComboBox->currentItem() ) { case Miles: result /= 63360; break; case Yards: result /= 36; break; case Feet: result /= 12; break; }
// set the result int decimals = decimalsSpinBox->value(); resultLineEdit->setText( QString::number( result, 'f', decimals ) ); numberLineEdit->setText( QString::number( input, 'f', decimals ) ); }
----------------------------------
Which, quite frankly, based on what I've read in TICPPV1 and from lurking the NG, and a little diddling around on my own, looks like a really crappy excuse for the power of C++.
After poking around a bit with g++ and QT, I came up with this:
-------------------------------------- $ cat metric_conversion.ui.h /****************************************************************************
** ui.h extension file, included from the uic-generated form implementation. ** ** If you want to add, delete, or rename functions or slots, use ** Qt Designer to update this file, preserving your code. ** ** You should not define a constructor or destructor in this file. ** Instead, write your code in functions called init() and destroy(). ** These will automatically be called by the form's constructor and ** destructor. *****************************************************************************/ #include // Added by Rich: #include #include using namespace std;void ConversionForm::init() { // Added by Rich: cout setText( "10" ); convert(); numberLineEdit->selectAll(); }
// Added by Rich: void ConversionForm::destroy() { cout currentItem() ) { case km: scaledInput *= 1000000; FromUnits = "km"; // this, and those below, make it break; // easy to report, below case m: scaledInput *= 1000; FromUnits = "m"; break; case cm: scaledInput *= 10; FromUnits = "cm"; break; }
//convert to inches double result = scaledInput * 0.0393701;
// like the above, for reporting string ToUnits = "In";
switch ( toComboBox->currentItem() ) { case Mi: result /= 63360; ToUnits = "Mi"; break; case Yd: result /= 36; ToUnits = "Yd"; break; case Ft: result /= 12; ToUnits = "Ft"; break; }
// set the result int decimals = decimalsSpinBox->value(); resultLineEdit->setText( QString::number( result, 'f', decimals ) ); numberLineEdit->setText( QString::number( input, 'f', decimals ) );
// I've added this part just to see console I/O simultaneously with pushing // buttons and schtuff. What a geek-gasm! cout text().toDouble()