diff options
author | Geir Vattekar <geir.vattekar@nokia.com> | 2011-01-21 06:32:05 (GMT) |
---|---|---|
committer | Geir Vattekar <geir.vattekar@nokia.com> | 2011-01-21 06:32:05 (GMT) |
commit | 04765969d74f4e3f323a4477c41b061e954f6df7 (patch) | |
tree | e50c296907d275bdb03761b501c7c72cb1c88504 /examples/tutorials | |
parent | c9be4ccfbd63323a2d70d341c9bc490a95195148 (diff) | |
download | Qt-04765969d74f4e3f323a4477c41b061e954f6df7.zip Qt-04765969d74f4e3f323a4477c41b061e954f6df7.tar.gz Qt-04765969d74f4e3f323a4477c41b061e954f6df7.tar.bz2 |
Doc: Added code for GettingStartedQt tutorial
Task-number: QTBUG-16609
Diffstat (limited to 'examples/tutorials')
13 files changed, 432 insertions, 0 deletions
diff --git a/examples/tutorials/gettingStarted/gsQt/gsqt.pro b/examples/tutorials/gettingStarted/gsQt/gsqt.pro new file mode 100755 index 0000000..46c4f06 --- /dev/null +++ b/examples/tutorials/gettingStarted/gsQt/gsqt.pro @@ -0,0 +1,14 @@ +TEMPLATE = subdirs + +SUBDIRS = part1 \ + part2 \ + part3 \ + part4 \ + part5 \ + part6 + +# install +sources.files = *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/tutorials/gettingStarted/gsQt +INSTALLS += sources + diff --git a/examples/tutorials/gettingStarted/gsQt/part1/main.cpp b/examples/tutorials/gettingStarted/gsQt/part1/main.cpp new file mode 100755 index 0000000..e1eabca --- /dev/null +++ b/examples/tutorials/gettingStarted/gsQt/part1/main.cpp @@ -0,0 +1,14 @@ + +#include <QtGui> + + +int main(int argv, char **args) +{ + QApplication app(argv, args); + + QTextEdit textEdit; + textEdit.show(); + + return app.exec(); +} + diff --git a/examples/tutorials/gettingStarted/gsQt/part1/part1.pro b/examples/tutorials/gettingStarted/gsQt/part1/part1.pro new file mode 100755 index 0000000..f52a633 --- /dev/null +++ b/examples/tutorials/gettingStarted/gsQt/part1/part1.pro @@ -0,0 +1,8 @@ +SOURCES = main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/tutorials/gettingStarted/gsQt/part1 +sources.files = $$SOURCES *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/tutorial/gettingStarted/gsQt/part1 +INSTALLS += target sources + diff --git a/examples/tutorials/gettingStarted/gsQt/part2/main.cpp b/examples/tutorials/gettingStarted/gsQt/part2/main.cpp new file mode 100755 index 0000000..2910310 --- /dev/null +++ b/examples/tutorials/gettingStarted/gsQt/part2/main.cpp @@ -0,0 +1,24 @@ + +#include <QtGui> + +int main(int argv, char **args) +{ + QApplication app(argv, args); + + QTextEdit textEdit; + QPushButton quitButton("&Quit"); + + QObject::connect(&quitButton, SIGNAL(clicked()), qApp, SLOT(quit())); + + QVBoxLayout layout; + layout.addWidget(&textEdit); + layout.addWidget(&quitButton); + + QWidget window; + window.setLayout(&layout); + + window.show(); + + return app.exec(); +} + diff --git a/examples/tutorials/gettingStarted/gsQt/part2/part2.pro b/examples/tutorials/gettingStarted/gsQt/part2/part2.pro new file mode 100755 index 0000000..383c3ce --- /dev/null +++ b/examples/tutorials/gettingStarted/gsQt/part2/part2.pro @@ -0,0 +1,9 @@ + +SOURCES = main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/tutorials/gettingStarted/gsQt/part2 +sources.files = $$SOURCES *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/tutorial/gettingStarted/gsQt/part2 +INSTALLS += target sources + diff --git a/examples/tutorials/gettingStarted/gsQt/part3/main.cpp b/examples/tutorials/gettingStarted/gsQt/part3/main.cpp new file mode 100755 index 0000000..238fb94 --- /dev/null +++ b/examples/tutorials/gettingStarted/gsQt/part3/main.cpp @@ -0,0 +1,58 @@ + +#include <QtGui> + +class Notepad : public QWidget +{ + Q_OBJECT + +public: + Notepad(); + +private slots: + void quit(); + +private: + QTextEdit *textEdit; + QPushButton *quitButton; + +}; + +Notepad::Notepad() +{ + textEdit = new QTextEdit; + quitButton = new QPushButton(tr("Quit")); + + connect(quitButton, SIGNAL(clicked()), this, SLOT(quit())); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(textEdit); + layout->addWidget(quitButton); + + setLayout(layout); + + setWindowTitle(tr("Notepad")); +} + +void Notepad::quit() +{ + QMessageBox messageBox; + messageBox.setWindowTitle(tr("Notepad")); + messageBox.setText(tr("Do you really want to quit?")); + messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + messageBox.setDefaultButton(QMessageBox::No); + if (messageBox.exec() == QMessageBox::Yes) + qApp->quit(); +} + +int main(int argv, char **args) +{ + QApplication app(argv, args); + + Notepad notepad; + notepad.show(); + + return app.exec(); +} + +#include "main.moc" + diff --git a/examples/tutorials/gettingStarted/gsQt/part3/part3.pro b/examples/tutorials/gettingStarted/gsQt/part3/part3.pro new file mode 100755 index 0000000..d194acb --- /dev/null +++ b/examples/tutorials/gettingStarted/gsQt/part3/part3.pro @@ -0,0 +1,9 @@ + +SOURCES = main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/tutorials/gettingStarted/gsQt/part3 +sources.files = $$SOURCES *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/tutorial/gettingStarted/gsQt/part3 +INSTALLS += target sources + diff --git a/examples/tutorials/gettingStarted/gsQt/part4/main.cpp b/examples/tutorials/gettingStarted/gsQt/part4/main.cpp new file mode 100755 index 0000000..6bc9638 --- /dev/null +++ b/examples/tutorials/gettingStarted/gsQt/part4/main.cpp @@ -0,0 +1,69 @@ + +#include <QtGui> + +class Notepad : public QMainWindow +{ + Q_OBJECT + +public: + Notepad(); + +private slots: + void load(); + void save(); + +private: + QTextEdit *textEdit; + + QAction *loadAction; + QAction *saveAction; + QAction *exitAction; + + QMenu *fileMenu; +}; + +Notepad::Notepad() +{ + + loadAction = new QAction(tr("&Load"), this); + saveAction = new QAction(tr("&Save"), this); + exitAction = new QAction(tr("E&xit"), this); + + connect(loadAction, SIGNAL(triggered()), this, SLOT(load())); + connect(saveAction, SIGNAL(triggered()), this, SLOT(save())); + connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + + fileMenu = menuBar()->addMenu(tr("&File")); + fileMenu->addAction(loadAction); + fileMenu->addAction(saveAction); + fileMenu->addSeparator(); + fileMenu->addAction(exitAction); + + textEdit = new QTextEdit; + setCentralWidget(textEdit); + + setWindowTitle(tr("Notepad")); +} + +void Notepad::load() +{ + +} + +void Notepad::save() +{ + +} + +int main(int argv, char **args) +{ + QApplication app(argv, args); + + Notepad notepad; + notepad.show(); + + return app.exec(); +}; + +#include "main.moc" + diff --git a/examples/tutorials/gettingStarted/gsQt/part4/part4.pro b/examples/tutorials/gettingStarted/gsQt/part4/part4.pro new file mode 100755 index 0000000..3de03ac --- /dev/null +++ b/examples/tutorials/gettingStarted/gsQt/part4/part4.pro @@ -0,0 +1,9 @@ + +SOURCES = main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/tutorials/gettingStarted/gsQt/part4 +sources.files = $$SOURCES *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/tutorial/gettingStarted/gsQt/part4 +INSTALLS += target sources + diff --git a/examples/tutorials/gettingStarted/gsQt/part5/main.cpp b/examples/tutorials/gettingStarted/gsQt/part5/main.cpp new file mode 100755 index 0000000..a97bab8 --- /dev/null +++ b/examples/tutorials/gettingStarted/gsQt/part5/main.cpp @@ -0,0 +1,105 @@ + +#include <QtGui> + +class Notepad : public QMainWindow +{ + Q_OBJECT + +public: + Notepad(); + +private slots: + void newDocument(); + void load(); + void save(); + + void documentChanged(int index); + +private: + QTextEdit *textEdit; + + QAction *newDocumentAction; + QAction *loadAction; + QAction *saveAction; + QAction *exitAction; + + QMenu *fileMenu; + + QDockWidget *dockWidget; + QListWidget *listWidget; + + QStringList documents; + int documentCount; +}; + +Notepad::Notepad() +{ + + newDocumentAction = new QAction(tr("&New"), this); + loadAction = new QAction(tr("&Load"), this); + saveAction = new QAction(tr("&Save"), this); + exitAction = new QAction(tr("E&xit"), this); + + connect(newDocumentAction, SIGNAL(triggered()), this, SLOT(newDocument())); + connect(loadAction, SIGNAL(triggered()), this, SLOT(load())); + connect(saveAction, SIGNAL(triggered()), this, SLOT(save())); + connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + + fileMenu = menuBar()->addMenu(tr("&File")); + fileMenu->addAction(newDocumentAction); + fileMenu->addAction(loadAction); + fileMenu->addAction(saveAction); + fileMenu->addSeparator(); + fileMenu->addAction(exitAction); + + textEdit = new QTextEdit; + setCentralWidget(textEdit); + + listWidget = new QListWidget; + + connect(listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(documentChanged(int))); + + dockWidget = new QDockWidget; + dockWidget->setWidget(listWidget); + + addDockWidget(Qt::LeftDockWidgetArea, dockWidget); + + documentCount = 0; + newDocument(); + + setWindowTitle(tr("Notepad")); +} + +void Notepad::documentChanged(int index) +{ + +} + +void Notepad::newDocument() +{ + listWidget->addItem(tr("Document %1").arg(documentCount++)); + documents.append(""); +} + +void Notepad::load() +{ + +} + +void Notepad::save() +{ + +} + +int main(int argv, char **args) +{ + QApplication app(argv, args); + + Notepad notepad; + notepad.show(); + + return app.exec(); +}; + +#include "main.moc" + diff --git a/examples/tutorials/gettingStarted/gsQt/part5/part5.pro b/examples/tutorials/gettingStarted/gsQt/part5/part5.pro new file mode 100755 index 0000000..711cac2 --- /dev/null +++ b/examples/tutorials/gettingStarted/gsQt/part5/part5.pro @@ -0,0 +1,9 @@ + +SOURCES = main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/tutorials/gettingStarted/gsQt/part5 +sources.files = $$SOURCES *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/tutorial/gettingStarted/gsQt/part5 +INSTALLS += target sources + diff --git a/examples/tutorials/gettingStarted/gsQt/part6/main.cpp b/examples/tutorials/gettingStarted/gsQt/part6/main.cpp new file mode 100755 index 0000000..ef1217b --- /dev/null +++ b/examples/tutorials/gettingStarted/gsQt/part6/main.cpp @@ -0,0 +1,95 @@ + +#include <QtGui> + +class Notepad : public QMainWindow +{ + Q_OBJECT + +public: + Notepad(); + +private slots: + void open(); + void save(); + +private: + QTextEdit *textEdit; + + QAction *openAction; + QAction *saveAction; + QAction *exitAction; + + QMenu *fileMenu; +}; + +Notepad::Notepad() +{ + + openAction = new QAction(tr("&Load"), this); + saveAction = new QAction(tr("&Save"), this); + exitAction = new QAction(tr("E&xit"), this); + + connect(openAction, SIGNAL(triggered()), this, SLOT(open())); + connect(saveAction, SIGNAL(triggered()), this, SLOT(save())); + connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + + fileMenu = menuBar()->addMenu(tr("&File")); + fileMenu->addAction(openAction); + fileMenu->addAction(saveAction); + fileMenu->addSeparator(); + fileMenu->addAction(exitAction); + + textEdit = new QTextEdit; + setCentralWidget(textEdit); + + setWindowTitle(tr("Notepad")); +} + +void Notepad::open() +{ + QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", + tr("Text Files (*.txt);;C++ Files (*.cpp *.h)")); + + if (fileName != "") { + QFile file(fileName); + if (!file.open(QIODevice::ReadOnly)) { + QMessageBox::critical(this, tr("Error"), tr("Could not open file")); + return; + } + QTextStream in(&file); + textEdit->setText(in.readAll()); + file.close(); + } +} + +void Notepad::save() +{ + + QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), "", + tr("Text Files (*.txt);;C++ Files (*.cpp *.h)")); + + if (fileName != "") { + QFile file(fileName); + if (!file.open(QIODevice::WriteOnly)) { + // error message + } else { + QTextStream stream(&file); + stream << textEdit->toPlainText(); + stream.flush(); + file.close(); + } + } +} + +int main(int argv, char **args) +{ + QApplication app(argv, args); + + Notepad notepad; + notepad.show(); + + return app.exec(); +} + +#include "main.moc" + diff --git a/examples/tutorials/gettingStarted/gsQt/part6/part6.pro b/examples/tutorials/gettingStarted/gsQt/part6/part6.pro new file mode 100755 index 0000000..a7861f9 --- /dev/null +++ b/examples/tutorials/gettingStarted/gsQt/part6/part6.pro @@ -0,0 +1,9 @@ + +SOURCES = main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/tutorials/gettingStarted/gsQt/part6 +sources.files = $$SOURCES *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/tutorial/gettingStarted/gsQt/part6 +INSTALLS += target sources + |