Results 1 to 3 of 3

Thread: C++ GUI Programming with Qt 4:the coordinate setter application

  1. #1
    Join Date
    Apr 2007
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1

    Default C++ GUI Programming with Qt 4:the coordinate setter application

    Hi everybody,
    i am a newbie and i am interested in the Coordinate Setter application in Chapter10 of Blanchette ´s book.In the book there is only a part of the code ,and i dont know how to make it work.

    This what i found in the book.what should i add to make it work?

    Qt Code:
    1. CoordinateSetter::CoordinateSetter(QList<QPointF> *coords,
    2. QWidget *parent)
    3. : QDialog(parent)
    4. {
    5. coordinates = coords;
    6. tableWidget = new QTableWidget(0, 2);
    7. tableWidget->setHorizontalHeaderLabels(
    8. QStringList() << tr("X") << tr("Y"));
    9. for (int row = 0; row < coordinates->count(); ++row) {
    10. QPointF point = coordinates->at(row);
    11. addRow();
    12. tableWidget->item(row, 0)->setText(QString::number(point.x()));
    13. tableWidget->item(row, 1)->setText(QString::number(point.y()));
    14. }
    15. ...
    16. }
    17.  
    18.  
    19. void CoordinateSetter::addRow()
    20. {
    21. int row = tableWidget->rowCount();
    22. tableWidget->insertRow(row);
    23. item0->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
    24. tableWidget->setItem(row, 0, item0);
    25. item1->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
    26. tableWidget->setItem(row, 1, item1);
    27. tableWidget->setCurrentItem(item0);
    28. }
    29.  
    30. void CoordinateSetter::done(int result)
    31. {
    32. if (result == QDialog::Accepted) {
    33. coordinates->clear();
    34. for (int row = 0; row < tableWidget->rowCount(); ++row) {
    35. double x = tableWidget->item(row, 0)->text().toDouble();
    36. double y = tableWidget->item(row, 1)->text().toDouble();
    37. coordinates->append(QPointF(x, y));
    38. }
    39. }
    40. QDialog::done(result);
    41. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: C++ GUI Programming with Qt 4:the coordinate setter application

    As far as I know all the examples are provided in the enclosed CD.
    The all should compile with out a problem.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Apr 2007
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1

    Default Re: C++ GUI Programming with Qt 4:the coordinate setter application

    thanks high_flyer.i have to get the cd.
    Last edited by adonis; 28th April 2007 at 10:14.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.