Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- main.cpp
- -------------
- #include "mainwindow.h"
- #include <QApplication>
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- MainWindow w;
- w.show();
- return a.exec();
- }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- mainwindow.h
- -------------
- #define MAINWINDOW_H
- #include <QMainWindow>
- #include "ui_mainwindow.h"
- namespace Ui {
- class MainWindow;
- }
- class MainWindow : public QMainWindow
- {
- Q_OBJECT
- public:
- explicit MainWindow(QWidget *parent = 0);
- ~MainWindow();
- protected slots:
- void on_toolButton_clicked();
- private:
- Ui::MainWindow *ui;
- };
- #endif // MAINWINDOW_H
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- mainwindow.cpp
- ---------------
- #include <QtWidgets>
- #include <QCoreApplication>
- #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::on_toolButton_clicked()
- {
- // create a generic FileDialog
- QFileDialog dialog(NULL, tr("Select a disk image"));
- dialog.setNameFilter(tr("Image Files (*.img *.IMG);;*.*"));
- dialog.setFileMode(QFileDialog::AnyFile); // should be default
- dialog.setViewMode(QFileDialog::Detail); // should be default
- dialog.setAcceptMode(QFileDialog::AcceptOpen); // should be default
- dialog.setOption(QFileDialog::DontConfirmOverwrite, true);
- QString fileLocation = NULL;
- if (dialog.exec())
- {
- // selectedFiles returns a QStringList - only expecting 1 filename,
- // so use the zero'th element from that list
- fileLocation = (dialog.selectedFiles())[0];
- }
- if (!fileLocation.isNull())
- {
- ui->label->setText(fileLocation);
- }
- }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- mainwindow.ui
- ----------------
- <?xml version="1.0" encoding="UTF-8"?>
- <ui version="4.0">
- <class>MainWindow</class>
- <widget class="QMainWindow" name="MainWindow">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>400</width>
- <height>300</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>MainWindow</string>
- </property>
- <widget class="QWidget" name="centralWidget">
- <widget class="QToolButton" name="toolButton">
- <property name="geometry">
- <rect>
- <x>180</x>
- <y>110</y>
- <width>25</width>
- <height>19</height>
- </rect>
- </property>
- <property name="text">
- <string>...</string>
- </property>
- </widget>
- <widget class="QLabel" name="label">
- <property name="geometry">
- <rect>
- <x>45</x>
- <y>170</y>
- <width>291</width>
- <height>21</height>
- </rect>
- </property>
- <property name="text">
- <string>TextLabel</string>
- </property>
- </widget>
- </widget>
- <widget class="QMenuBar" name="menuBar">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>400</width>
- <height>21</height>
- </rect>
- </property>
- </widget>
- <widget class="QToolBar" name="mainToolBar">
- <attribute name="toolBarArea">
- <enum>TopToolBarArea</enum>
- </attribute>
- <attribute name="toolBarBreak">
- <bool>false</bool>
- </attribute>
- </widget>
- <widget class="QStatusBar" name="statusBar"/>
- </widget>
- <layoutdefault spacing="6" margin="11"/>
- <resources/>
- <connections/>
- </ui>
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- dlgTest.pro
- -------------
- #-------------------------------------------------
- #
- # Project created by QtCreator 2014-04-21T15:21:13
- #
- #-------------------------------------------------
- QT += core gui
- greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
- TARGET = dlgTest
- TEMPLATE = app
- SOURCES += main.cpp\
- mainwindow.cpp
- HEADERS += mainwindow.h
- FORMS += mainwindow.ui
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement