Yes i can ;-)
You can select all with mouse, you must not use the keyboard.
But When you press Enter on your Keyboard to save the file and not click with Mouse on "Save" Button it crashes
When you click with Mouse the "Save" Button int works.
.pro
#-------------------------------------------------
#
# Project created by QtCreator 2016-12-05T11:36:37
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = dialogtest
TEMPLATE = app
SOURCES += main.cpp\
exportdialog.cpp
HEADERS += exportdialog.h
FORMS += exportdialog.ui
#-------------------------------------------------
#
# Project created by QtCreator 2016-12-05T11:36:37
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = dialogtest
TEMPLATE = app
SOURCES += main.cpp\
exportdialog.cpp
HEADERS += exportdialog.h
FORMS += exportdialog.ui
To copy to clipboard, switch view to plain text mode
main.cpp
#include "exportdialog.h"
#include <QApplication>
#include <QMessageBox>
int main(int argc, char *argv[])
{
ExportDialog *dlg = new ExportDialog(false);
if (dlg
->exec
() == QDialog::Accepted ) { QString filename
= dlg
->getFilename
();
if (true /* doExport(filename, dlg->getFrom(), dlg->getTo()) */) {
} else {
}
}
delete dlg;
return a.exec();
}
#include "exportdialog.h"
#include <QApplication>
#include <QMessageBox>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ExportDialog *dlg = new ExportDialog(false);
if (dlg->exec() == QDialog::Accepted ) {
QString filename = dlg->getFilename();
if (true /* doExport(filename, dlg->getFrom(), dlg->getTo()) */) {
QMessageBox::information(0, "Export", QString("saved to %1").arg(filename));
} else {
QMessageBox::warning(0, "Export", QString("Can't save to %1").arg(filename));
}
}
delete dlg;
return a.exec();
}
To copy to clipboard, switch view to plain text mode
exportdialog.cpp
#include "exportdialog.h"
#include <QFileDialog>
#include "ui_exportdialog.h"
ExportDialog
::ExportDialog( bool save2dir,
QWidget *parent
) : QDialog(parent
), ui
(new Ui
::ExportDialog), m_saveTodir
(save2dir
) {
ui->setupUi(this);
m_filename = "";
QDate date
= QDate::fromString(sDate,
"yyyy-MM-dd");
ui
->dateEditTo
->setDate
(QDate::currentDate());
ui->dateEditFrom->setDate(date);
m_fromDT->setDate(date);
m_toDT
->setDate
(QDate::currentDate());
m_toDT
->setTime
(QTime::fromString("23:59:59"));
connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(onCancelButton_clicked()));
connect(ui->exportButton, SIGNAL(clicked()), this, SLOT(onExportButton_clicked()));
connect(ui
->dateEditFrom,
SIGNAL(dateChanged
(QDate)),
this,
SLOT(onDateEditFrom_dateChanged
(QDate)));
connect(ui
->dateEditTo,
SIGNAL(dateChanged
(QDate)),
this,
SLOT(onDateEditTo_dateChanged
(QDate)));
}
ExportDialog::~ExportDialog()
{
delete ui;
delete m_fromDT;
delete m_toDT;
}
QString ExportDialog
::getFilename() {
return m_filename;
}
{
return m_fromDT->toString(Qt::ISODate);
}
{
return m_toDT->toString(Qt::ISODate);
}
void ExportDialog::onCancelButton_clicked()
{
this->close();
}
void ExportDialog
::onDateEditTo_dateChanged(const QDate &date
) {
m_toDT->setDate(date);
m_toDT
->setTime
(QTime::fromString("23:59:59"));
}
void ExportDialog
::onDateEditFrom_dateChanged(const QDate &date
) {
m_fromDT->setDate(date);
}
void ExportDialog::onExportButton_clicked()
{
if (m_saveTodir) {
m_filename
= QFileDialog::getExistingDirectory(this,
"Save to ...");
} else {
m_filename
= QFileDialog::getSaveFileName(this,
"save",
"",
"Journal (*.csv)");
}
if (m_filename.isNull())
return;
}
#include "exportdialog.h"
#include <QFileDialog>
#include "ui_exportdialog.h"
ExportDialog::ExportDialog( bool save2dir, QWidget *parent)
: QDialog(parent), ui(new Ui::ExportDialog), m_saveTodir(save2dir)
{
ui->setupUi(this);
m_fromDT = new QDateTime;
m_toDT = new QDateTime;
m_filename = "";
QString sDate = QString("%1-01-01").arg(QDate::currentDate().year());
QDate date = QDate::fromString(sDate,"yyyy-MM-dd");
ui->dateEditTo->setDate(QDate::currentDate());
ui->dateEditFrom->setDate(date);
m_fromDT->setDate(date);
m_toDT->setDate(QDate::currentDate());
m_toDT->setTime(QTime::fromString("23:59:59"));
connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(onCancelButton_clicked()));
connect(ui->exportButton, SIGNAL(clicked()), this, SLOT(onExportButton_clicked()));
connect(ui->dateEditFrom, SIGNAL(dateChanged(QDate)), this, SLOT(onDateEditFrom_dateChanged(QDate)));
connect(ui->dateEditTo, SIGNAL(dateChanged(QDate)), this, SLOT(onDateEditTo_dateChanged(QDate)));
}
ExportDialog::~ExportDialog()
{
delete ui;
delete m_fromDT;
delete m_toDT;
}
QString ExportDialog::getFilename()
{
return m_filename;
}
QString ExportDialog::getFrom()
{
return m_fromDT->toString(Qt::ISODate);
}
QString ExportDialog::getTo()
{
return m_toDT->toString(Qt::ISODate);
}
void ExportDialog::onCancelButton_clicked()
{
this->close();
}
void ExportDialog::onDateEditTo_dateChanged(const QDate &date)
{
m_toDT->setDate(date);
m_toDT->setTime(QTime::fromString("23:59:59"));
}
void ExportDialog::onDateEditFrom_dateChanged(const QDate &date)
{
m_fromDT->setDate(date);
}
void ExportDialog::onExportButton_clicked()
{
if (m_saveTodir) {
m_filename = QFileDialog::getExistingDirectory(this, "Save to ...");
} else {
m_filename = QFileDialog::getSaveFileName(this, "save", "", "Journal (*.csv)");
}
if (m_filename.isNull())
return;
QDialog::accept();
}
To copy to clipboard, switch view to plain text mode
eportdialog.h
#ifndef EXPORTDIALOG_H
#define EXPORTDIALOG_H
#include <QDialog>
namespace Ui {
class ExportDialog;
}
class ExportDialog
: public QDialog{
Q_OBJECT
public:
ExportDialog
(bool save2dir,
QWidget *parent
= 0);
~ExportDialog();
private slots:
void onCancelButton_clicked();
void onDateEditTo_dateChanged
(const QDate &date
);
void onDateEditFrom_dateChanged
(const QDate &date
);
void onExportButton_clicked();
private:
Ui::ExportDialog *ui;
bool m_saveTodir;
};
#endif // EXPORTDIALOG_H
#ifndef EXPORTDIALOG_H
#define EXPORTDIALOG_H
#include <QDialog>
namespace Ui {
class ExportDialog;
}
class ExportDialog : public QDialog
{
Q_OBJECT
public:
ExportDialog(bool save2dir, QWidget *parent = 0);
~ExportDialog();
QString getFilename();
QString getFrom();
QString getTo();
private slots:
void onCancelButton_clicked();
void onDateEditTo_dateChanged(const QDate &date);
void onDateEditFrom_dateChanged(const QDate &date);
void onExportButton_clicked();
private:
Ui::ExportDialog *ui;
bool m_saveTodir;
QDateTime *m_fromDT;
QDateTime *m_toDT;
QString m_filename;
};
#endif // EXPORTDIALOG_H
To copy to clipboard, switch view to plain text mode
exportdialog.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ExportDialog</class>
<widget class="QDialog" name="ExportDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>340</width>
<height>191</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="exportLabel">
<property name="font">
<font>
<family>Arial</family>
<pointsize>12</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Exportieren</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QDateEdit" name="dateEditFrom">
<property name="accessibleName">
<string notr="true"/>
</property>
<property name="accessibleDescription">
<string notr="true"/>
</property>
<property name="currentSection">
<enum>QDateTimeEdit::DaySection</enum>
</property>
<property name="calendarPopup">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>-</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QDateEdit" name="dateEditTo">
<property name="accessibleName">
<string notr="true"/>
</property>
<property name="accessibleDescription">
<string notr="true"/>
</property>
<property name="calendarPopup">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="exportButton">
<property name="minimumSize">
<size>
<width>150</width>
<height>60</height>
</size>
</property>
<property name="text">
<string>Export</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelButton">
<property name="minimumSize">
<size>
<width>150</width>
<height>60</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Cancel</string>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ExportDialog</class>
<widget class="QDialog" name="ExportDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>340</width>
<height>191</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="exportLabel">
<property name="font">
<font>
<family>Arial</family>
<pointsize>12</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Exportieren</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QDateEdit" name="dateEditFrom">
<property name="accessibleName">
<string notr="true"/>
</property>
<property name="accessibleDescription">
<string notr="true"/>
</property>
<property name="currentSection">
<enum>QDateTimeEdit::DaySection</enum>
</property>
<property name="calendarPopup">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>-</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QDateEdit" name="dateEditTo">
<property name="accessibleName">
<string notr="true"/>
</property>
<property name="accessibleDescription">
<string notr="true"/>
</property>
<property name="calendarPopup">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="exportButton">
<property name="minimumSize">
<size>
<width>150</width>
<height>60</height>
</size>
</property>
<property name="text">
<string>Export</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelButton">
<property name="minimumSize">
<size>
<width>150</width>
<height>60</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Cancel</string>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
To copy to clipboard, switch view to plain text mode
lg Chris
Added after 4 minutes:
When i do this ...
main.cpp
#include "exportdialog.h"
#include <QApplication>
#include <QMessageBox>
int main(int argc, char *argv[])
{
ExportDialog *dlg = new ExportDialog(false);
if (dlg
->exec
() == QDialog::Accepted ) { QString filename
= dlg
->getFilename
();
if (true /* doExport(filename, dlg->getFrom(), dlg->getTo()) */) {
delete dlg;
} else {
delete dlg;
}
}
return a.exec();
}
#include "exportdialog.h"
#include <QApplication>
#include <QMessageBox>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ExportDialog *dlg = new ExportDialog(false);
if (dlg->exec() == QDialog::Accepted ) {
QString filename = dlg->getFilename();
if (true /* doExport(filename, dlg->getFrom(), dlg->getTo()) */) {
delete dlg;
QMessageBox::information(0, "Export", QString("saved to %1").arg(filename));
} else {
delete dlg;
QMessageBox::warning(0, "Export", QString("Can't save to %1").arg(filename));
}
}
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks