×
Namespaces

Variants
Actions
(Difference between revisions)

How to create alarm list in Qt

From Nokia Developer Wiki
Jump to: navigation, search
somnathbanik (Talk | contribs)
hamishwillee (Talk | contribs)
m (Update abstract)
Line 1: Line 1:
 
[[Category:Qt]]
 
[[Category:Qt]]
==Overview==
+
{{Abstract|This code example shows shows how I created a basic layout for listing and enabling alarms (note that the actual alarm code is not included). The examples lays out a number of {{Icode|QWidgets}} in a MainWindow application, including {{Icode|QLabel}}, {{Icode|QCheckBox}}, and {{Icode|QTimeEdit}}. }}
  
{{Abstract|The code example given below is used to make the Alarm list window in Qt.Here in the below code I have used this {{Icode|QLabel}}, {{Icode|QCheckBox}}, and {{Icode|QTimeEdit}} widgets to make the page of Alarm list in Qt.}}
 
 
Also I have connected the {{Icode|QCheckBox}} with the {{Icode|QTimeEdit}} using '''signal and slot''' mechanism.
 
Also I have connected the {{Icode|QCheckBox}} with the {{Icode|QTimeEdit}} using '''signal and slot''' mechanism.
For more information go to this link.[http://wiki.forum.nokia.com/index.php/Understanding_signal_and_slot_in_Qt Understanding_signal_and_slot_in_Qt]
 
  
 
==Prerequisite==
 
==Prerequisite==
  
* Before you read this article go to this link and read this article for better understanding.[http://wiki.forum.nokia.com/index.php/How_to_create_your_first_Qt_application. How_to_create_your_first_Qt_application]
+
* Before you read this article go to this link and read this article : [[How to create your first Qt application.]]
 
+
* Download and install the [[Nokia Qt SDK]]  
* Here it is assumed that a user had properly set the Qt application development environment. And also [http://wiki.forum.nokia.com/index.php/Nokia_Qt_SDK Qt SDK] for windows is also installed.
+
 
+
* Check all the installation steps as described here : [http://wiki.forum.nokia.com/index.php/Qt_Creator_and_on_device_debugging_with_AppTRK Setting up Qt Development environment]
+
  
 
==Header file==
 
==Header file==
Line 201: Line 196:
 
==Source code==
 
==Source code==
 
The full source code presented in this article is available here [[File:Alarmlist.zip]]
 
The full source code presented in this article is available here [[File:Alarmlist.zip]]
 +
 +
==Further Information ==
 +
* [[Understanding signal and slot in Qt]]
  
 
--[[User:Rahulvala|rahul]] 06:34, 6 April 2010 (UTC)
 
--[[User:Rahulvala|rahul]] 06:34, 6 April 2010 (UTC)

Revision as of 04:46, 5 May 2011

This code example shows shows how I created a basic layout for listing and enabling alarms (note that the actual alarm code is not included). The examples lays out a number of QWidgets in a MainWindow application, including QLabel, QCheckBox, and QTimeEdit.

Also I have connected the QCheckBox with the QTimeEdit using signal and slot mechanism.

Contents

Prerequisite

Header file

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
 
#include <QMainWindow>
 
namespace Ui {
class MainWindow;
}
 
class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
 
protected:
void changeEvent(QEvent *e);
 
private:
Ui::MainWindow *ui;
};
 
#endif // MAINWINDOW_H

Source file

#include "mainwindow.h"
#include "ui_mainwindow.h"
 
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
 
MainWindow::~MainWindow()
{
delete ui;
}
 
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}


ui_mainwindow.cpp

#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H
 
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QCheckBox>
#include <QtGui/QGroupBox>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QMainWindow>
#include <QtGui/QMenuBar>
#include <QtGui/QStatusBar>
#include <QtGui/QTimeEdit>
#include <QtGui/QToolBar>
#include <QtGui/QWidget>
 
QT_BEGIN_NAMESPACE
 
class Ui_MainWindow
{
public:
QWidget *centralWidget;
QGroupBox *groupBox;
QLabel *label;
QLabel *label_2;
QLabel *label_3;
QCheckBox *checkBox;
QCheckBox *checkBox_2;
QCheckBox *checkBox_3;
QTimeEdit *timeEdit;
QTimeEdit *timeEdit_2;
QTimeEdit *timeEdit_3;
QMenuBar *menuBar;
QToolBar *mainToolBar;
QStatusBar *statusBar;
 
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(600, 400);
centralWidget = new QWidget(MainWindow);
centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
groupBox = new QGroupBox(centralWidget);
groupBox->setObjectName(QString::fromUtf8("groupBox"));
groupBox->setGeometry(QRect(10, 20, 261, 251));
label = new QLabel(groupBox);
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(20, 40, 46, 13));
label_2 = new QLabel(groupBox);
label_2->setObjectName(QString::fromUtf8("label_2"));
label_2->setGeometry(QRect(20, 100, 46, 13));
label_3 = new QLabel(groupBox);
label_3->setObjectName(QString::fromUtf8("label_3"));
label_3->setGeometry(QRect(20, 170, 46, 13));
checkBox = new QCheckBox(groupBox);
checkBox->setObjectName(QString::fromUtf8("checkBox"));
checkBox->setGeometry(QRect(80, 40, 70, 17));
checkBox_2 = new QCheckBox(groupBox);
checkBox_2->setObjectName(QString::fromUtf8("checkBox_2"));
checkBox_2->setGeometry(QRect(80, 100, 70, 17));
checkBox_3 = new QCheckBox(groupBox);
checkBox_3->setObjectName(QString::fromUtf8("checkBox_3"));
checkBox_3->setGeometry(QRect(80, 170, 70, 17));
timeEdit = new QTimeEdit(groupBox);
timeEdit->setObjectName(QString::fromUtf8("timeEdit"));
timeEdit->setGeometry(QRect(130, 40, 118, 22));
timeEdit_2 = new QTimeEdit(groupBox);
timeEdit_2->setObjectName(QString::fromUtf8("timeEdit_2"));
timeEdit_2->setGeometry(QRect(130, 100, 118, 22));
timeEdit_3 = new QTimeEdit(groupBox);
timeEdit_3->setObjectName(QString::fromUtf8("timeEdit_3"));
timeEdit_3->setGeometry(QRect(130, 160, 118, 22));
MainWindow->setCentralWidget(centralWidget);
menuBar = new QMenuBar(MainWindow);
menuBar->setObjectName(QString::fromUtf8("menuBar"));
menuBar->setGeometry(QRect(0, 0, 600, 20));
MainWindow->setMenuBar(menuBar);
mainToolBar = new QToolBar(MainWindow);
mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
statusBar = new QStatusBar(MainWindow);
statusBar->setObjectName(QString::fromUtf8("statusBar"));
MainWindow->setStatusBar(statusBar);
 
retranslateUi(MainWindow);
 
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
 
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
groupBox->setTitle(QApplication::translate("MainWindow", "Alarm List", 0, QApplication::UnicodeUTF8));
label->setText(QApplication::translate("MainWindow", "Alarm 1", 0, QApplication::UnicodeUTF8));
label_2->setText(QApplication::translate("MainWindow", "Alarm 2", 0, QApplication::UnicodeUTF8));
label_3->setText(QApplication::translate("MainWindow", "Alarm 2", 0, QApplication::UnicodeUTF8));
checkBox->setText(QString());
checkBox_2->setText(QString());
checkBox_3->setText(QString());
} // retranslateUi
 
};
 
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
 
QT_END_NAMESPACE
 
#endif // UI_MAINWINDOW_H

output window

This code snippet will reflect the output given below.When QCheckBox is ticked at that time time available for editing.

Outputalarm.jpg

Source code

The full source code presented in this article is available here File:Alarmlist.zip

Further Information

--rahulvala 06:34, 6 April 2010 (UTC)

99 page views in the last 30 days.