Results 1 to 7 of 7

Thread: How to display my application gui

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2011
    Posts
    67
    Thanks
    22
    Thanked 5 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default How to display my application gui

    I have made an application and it has a Qtableview,four form fields of Qlinedit,Qgridlayout and five buttons.The application builds without any errors but exits when i try to run it with the windows error message : "smith.exe has encountered a problem and needs to close. We are sorry for the inconvenience.".

    Other examples i have run correctly.

    Here is the code.

    smith.h
    Qt Code:
    1. #ifndef SMITH_H
    2. #define SMITH_H
    3.  
    4. #include <QWidget>
    5.  
    6. QT_BEGIN_NAMESPACE
    7. class QLabel;
    8. class QLineEdit;
    9. class QTableView;
    10. QT_END_NAMESPACE
    11.  
    12. class smith : public QWidget
    13. {
    14. Q_OBJECT
    15.  
    16. public:
    17. smith(QWidget *parent = 0);
    18.  
    19. private:
    20.  
    21. void setupModel();
    22.  
    23. QSqlTableModel *tableModel;
    24. QTableView *tableView;
    25. QLabel *fnLabel;
    26. QLabel *lnLabel;
    27. QLabel *countryLabel;
    28. QLabel *cityLabel;
    29. QLineEdit *fEdit;
    30. QLineEdit *lnEdit;
    31. QLineEdit *cEdit;
    32. QLineEdit *cityEdit;
    33. QPushButton *newButton;
    34. QPushButton *nextButton;
    35. QPushButton *previousButton;
    36. QPushButton *saveButton;
    37. QPushButton *deleteButton;
    38.  
    39. private slots:
    40. void on_deleteButton_clicked();
    41. void on_saveButton_clicked();
    42. void on_newButton_clicked();
    43. };
    44.  
    45. #endif // SMITH_H
    To copy to clipboard, switch view to plain text mode 

    smith.cpp

    Qt Code:
    1. #include <QtGui>
    2. #include <QtSql>
    3. #include "smith.h"
    4.  
    5. smith::smith(QWidget *parent) :
    6. QWidget(parent)
    7. {
    8.  
    9. setupModel();
    10.  
    11. QLabel *fnLabel = new QLabel(tr("First Name:"));
    12. fEdit = new QLineEdit;
    13. fEdit->setReadOnly(true);
    14.  
    15. QLabel *lnLabel = new QLabel(tr("Last Name:"));
    16. lnEdit = new QLineEdit;
    17. lnEdit->setReadOnly(true);
    18.  
    19. QLabel *countryLabel = new QLabel(tr("Country:"));
    20. cEdit = new QLineEdit;
    21. cEdit->setReadOnly(true);
    22.  
    23. QLabel *cityLabel = new QLabel(tr("City:"));
    24. cityEdit = new QLineEdit;
    25. cityEdit->setReadOnly(true);
    26.  
    27. newButton = new QPushButton(tr("&New"));
    28. nextButton = new QPushButton(tr("&Next"));
    29. previousButton = new QPushButton(tr("&Previous"));
    30. saveButton = new QPushButton(tr("&Save"));
    31. deleteButton = new QPushButton(tr("&Delete"));
    32.  
    33. connect(newButton, SIGNAL(clicked()), this, SLOT(on_newButton_clicked()));
    34. connect(nextButton, SIGNAL(clicked()), mapper, SLOT(toNext()));
    35. connect(previousButton, SIGNAL(clicked()), mapper, SLOT(toPrevious()));
    36. connect(saveButton, SIGNAL(clicked()), this, SLOT(on_saveButton_clicked()));
    37. connect(deleteButton, SIGNAL(clicked()), this, SLOT(on_deleteButton_clicked()));
    38.  
    39. QGridLayout *mainLayout = new QGridLayout;
    40. mainLayout->addWidget(tableView);
    41. mainLayout->addWidget(fnLabel);
    42. mainLayout->addWidget(fEdit);
    43. mainLayout->addWidget(lnLabel);
    44. mainLayout->addWidget(lnEdit);
    45. mainLayout->addWidget(countryLabel);
    46. mainLayout->addWidget(cEdit);
    47. mainLayout->addWidget(cityLabel);
    48. mainLayout->addWidget(cityEdit);
    49. mainLayout->addWidget(newButton);
    50. mainLayout->addWidget(nextButton);
    51. mainLayout->addWidget(previousButton);
    52. mainLayout->addWidget(saveButton);
    53. mainLayout->addWidget(deleteButton);
    54.  
    55. setLayout(mainLayout);
    56. setWindowTitle(tr("Application Layout"));
    57.  
    58.  
    59. //Model setup
    60. tableModel = new QSqlTableModel(this);
    61. tableModel->setEditStrategy(QSqlTableModel::OnFieldChange);
    62. tableModel->setTable("application");
    63. tableModel->select();
    64. tableModel->setHeaderData(0, Qt::Horizontal, tr("First Name"));
    65. tableModel->setHeaderData(1, Qt::Horizontal, tr("Last Name"));
    66. tableModel->setHeaderData(2, Qt::Horizontal, tr("Country"));
    67. tableModel->setHeaderData(3, Qt::Horizontal, tr("City"));
    68.  
    69. fnLabel->setBuddy(fEdit);
    70. lnLabel->setBuddy(lnEdit);
    71. countryLabel->setBuddy(cEdit);
    72. cityLabel->setBuddy(cityEdit);
    73.  
    74. //Mapper
    75. mapper = new QDataWidgetMapper(this);
    76. mapper->setModel(tableModel);
    77. mapper->addMapping(fEdit, 0);
    78. mapper->addMapping(lnEdit, 1);
    79. mapper->addMapping(cEdit, 2);
    80. mapper->addMapping(cityEdit, 3);
    81. mapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
    82. mapper->toFirst();
    83.  
    84.  
    85. //TableView
    86. tableView = new QTableView(this);
    87. tableView->setModel(tableModel);
    88. tableView->resizeColumnsToContents();
    89. tableView->setWindowTitle("Application Data");
    90. }
    91.  
    92. void smith::setupModel()
    93. {
    94. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    95. db.setDatabaseName("smith.DAT");
    96. if (!db.open()) {
    97. QMessageBox::critical(0, tr("Cannot open database"),
    98. tr("Unable to establish a database connection.\n"
    99. "This example needs SQLite support. Please read "
    100. "the Qt SQL driver documentation for information how "
    101. "to build it."), QMessageBox::Cancel);
    102. return;
    103. }
    104. }
    105. void smith::on_newButton_clicked()
    106. {
    107.  
    108. }
    109.  
    110.  
    111. void smith::on_saveButton_clicked()
    112. {
    113.  
    114. }
    115.  
    116. void smith::on_deleteButton_clicked()
    117. {
    118.  
    119. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "smith.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. smith smith;
    8. smith.show();
    9.  
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    How do i get the qtableview,the buttons and the forms to display correctly?.
    Last edited by thefatladysingsopera; 27th July 2011 at 15:35.

Similar Threads

  1. OSD (On Screen Display) application on Qt Embedded
    By sundar.subramaniyan in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 17th July 2011, 17:32
  2. Launching GUI application on different X11 display
    By basy in forum Installation and Deployment
    Replies: 3
    Last Post: 3rd December 2010, 20:21
  3. Replies: 6
    Last Post: 19th September 2010, 05:42
  4. Replies: 0
    Last Post: 14th April 2010, 12:21
  5. Application doesn't display images
    By satoshi in forum Qt Programming
    Replies: 3
    Last Post: 2nd January 2010, 11:33

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.