I'm trying to build a GUI app, and I'm doing this through Qt. I also want to create a multi window application: I want that when I hit a button the other window shows up ("hiding" the previous one). Is that a GDI?
So far, I have create a .ui file for every window I want (currently 4), and I'm trying to connect them that way (the main window, with the other 3).
How could I do that?
I'm sending the file of the program in order to make my problema more undestandable:
main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
StudyWindow s;
QStackedWidget *stackedWidget = new QStackedWidget;
stackedWidget->addWidget(w);
stackedWidget->addWidget(s);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(stackedWidget);
setLayout(layout);
w.show();
return a.exec();
}
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ConnectStuff();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::ConnectStuff()
{
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QPushButton>
#include <QLayout>
#include <QStackedWidget>
#include "study.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
void ConnectStuff();
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
study.h
#ifndef STUDYWINDOW_H
#define STUDYWINDOW_H
#include <QMainWindow>
#include <QPushButton>
namespace Ui {
class StudyWindow;
}
class StudyWindow : public QMainWindow
{
Q_OBJECT
public:
explicit StudyWindow(QWidget *parent = 0);
~StudyWindow();
private:
Ui::StudyWindow *ui;
};
#endif // STUDYWINDOW_H
ui_Study.h
/********************************************************************************
** Form generated from reading UI file 'Study.ui'
**
** Created: Tue 20. Mar 20:10:56 2012
** by: Qt User Interface Compiler version 4.7.4
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_STUDY_H
#define UI_STUDY_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QHeaderView>
#include <QtGui/QMainWindow>
#include <QtGui/QMenu>
#include <QtGui/QMenuBar>
#include <QtGui/QPushButton>
#include <QtGui/QStatusBar>
#include <QtGui/QTreeWidget>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class Ui_StudyWindow
{
public:
QAction *actionVoltar;
QAction *actionSair;
QWidget *centralwidget;
QTreeWidget *treeWidget;
QPushButton *pushButton;
QMenuBar *menubar;
QMenu *menuVoltar;
QStatusBar *statusbar;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(800, 600);
actionVoltar = new QAction(MainWindow);
actionVoltar->setObjectName(QString::fromUtf8("actionVoltar"));
actionSair = new QAction(MainWindow);
actionSair->setObjectName(QString::fromUtf8("actionSair"));
centralwidget = new QWidget(MainWindow);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
treeWidget = new QTreeWidget(centralwidget);
QFont font;
font.setPointSize(8);
font.setBold(true);
font.setWeight(75);
QTreeWidgetItem *__qtreewidgetitem = new QTreeWidgetItem();
__qtreewidgetitem->setFont(0, font);
treeWidget->setHeaderItem(__qtreewidgetitem);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
new QTreeWidgetItem(treeWidget);
treeWidget->setObjectName(QString::fromUtf8("treeWidget"));
treeWidget->setGeometry(QRect(0, 110, 161, 451));
pushButton = new QPushButton(centralwidget);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
pushButton->setGeometry(QRect(0, 0, 75, 23));
MainWindow->setCentralWidget(centralwidget);
menubar = new QMenuBar(MainWindow);
menubar->setObjectName(QString::fromUtf8("menubar"));
menubar->setGeometry(QRect(0, 0, 800, 21));
menuVoltar = new QMenu(menubar);
menuVoltar->setObjectName(QString::fromUtf8("menuVoltar"));
MainWindow->setMenuBar(menubar);
statusbar = new QStatusBar(MainWindow);
statusbar->setObjectName(QString::fromUtf8("statusbar"));
MainWindow->setStatusBar(statusbar);
menubar->addAction(menuVoltar->menuAction());
menuVoltar->addAction(actionVoltar);
menuVoltar->addSeparator();
menuVoltar->addAction(actionSair);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
actionVoltar->setText(QApplication::translate("MainWindow", "Voltar", 0, QApplication::UnicodeUTF8));
actionSair->setText(QApplication::translate("MainWindow", "Sair", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem = treeWidget->headerItem();
___qtreewidgetitem->setText(1, QApplication::translate("MainWindow", "Items", 0, QApplication::UnicodeUTF8));
___qtreewidgetitem->setText(0, QApplication::translate("MainWindow", "Mat\303\251ria", 0, QApplication::UnicodeUTF8));
const bool __sortingEnabled = treeWidget->isSortingEnabled();
treeWidget->setSortingEnabled(false);
QTreeWidgetItem *___qtreewidgetitem1 = treeWidget->topLevelItem(0);
___qtreewidgetitem1->setText(0, QApplication::translate("MainWindow", "Portugu\303\252s", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem2 = treeWidget->topLevelItem(1);
___qtreewidgetitem2->setText(0, QApplication::translate("MainWindow", "Reda\303\247\303\243o", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem3 = treeWidget->topLevelItem(2);
___qtreewidgetitem3->setText(0, QApplication::translate("MainWindow", "Matem\303\241tica", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem4 = treeWidget->topLevelItem(3);
___qtreewidgetitem4->setText(0, QApplication::translate("MainWindow", "Biologia", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem5 = treeWidget->topLevelItem(4);
___qtreewidgetitem5->setText(0, QApplication::translate("MainWindow", "F\303\255sica", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem6 = treeWidget->topLevelItem(5);
___qtreewidgetitem6->setText(0, QApplication::translate("MainWindow", "Qu\303\255mica", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem7 = treeWidget->topLevelItem(6);
___qtreewidgetitem7->setText(0, QApplication::translate("MainWindow", "Hist\303\263ria", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem8 = treeWidget->topLevelItem(7);
___qtreewidgetitem8->setText(0, QApplication::translate("MainWindow", "Geografia", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem9 = treeWidget->topLevelItem(8);
___qtreewidgetitem9->setText(0, QApplication::translate("MainWindow", "Ingl\303\252s", 0, QApplication::UnicodeUTF8));
QTreeWidgetItem *___qtreewidgetitem10 = treeWidget->topLevelItem(9);
___qtreewidgetitem10->setText(0, QApplication::translate("MainWindow", "Espanhol", 0, QApplication::UnicodeUTF8));
treeWidget->setSortingEnabled(__sortingEnabled);
pushButton->setText(QApplication::translate("MainWindow", "Cansei!", 0, QApplication::UnicodeUTF8));
menuVoltar->setTitle(QApplication::translate("MainWindow", "Arquivo", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class StudyWindow: public Ui_StudyWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_STUDY_H
ui_mainwindow.h
/********************************************************************************
** Form generated from reading UI file 'mainwindow.ui'
**
** Created: Tue 20. Mar 20:10:56 2012
** by: Qt User Interface Compiler version 4.7.4
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QGroupBox>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QMainWindow>
#include <QtGui/QMenu>
#include <QtGui/QMenuBar>
#include <QtGui/QPlainTextEdit>
#include <QtGui/QPushButton>
#include <QtGui/QStatusBar>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public slots:
public:
QAction *actionAjuda;
QAction *actionLista_de;
QAction *actionSair;
QWidget *centralwidget;
QPushButton *pshBStudy;
QPushButton *pshBSimulator;
QPushButton *pshBExamCalen;
QPushButton *pshBReadOfDay;
QLabel *labelTitle;
QPlainTextEdit *plainTextNews;
QLabel *labelNews;
QGroupBox *groupBox;
QLabel *labelCollege;
QLabel *labelCourse;
QLabel *labelMemSince;
QLabel *labelLoggedWith;
QLabel *labelBP;
QStatusBar *statusbar;
QMenuBar *menuBar;
QMenu *menuArquivo;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(800, 600);
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(MainWindow->sizePolicy().hasHeightForWidth());
MainWindow->setSizePolicy(sizePolicy);
actionAjuda = new QAction(MainWindow);
actionAjuda->setObjectName(QString::fromUtf8("actionAjuda"));
actionLista_de = new QAction(MainWindow);
actionLista_de->setObjectName(QString::fromUtf8("actionLista_de"));
actionSair = new QAction(MainWindow);
actionSair->setObjectName(QString::fromUtf8("actionSair"));
centralwidget = new QWidget(MainWindow);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
pshBStudy = new QPushButton(centralwidget);
pshBStudy->setObjectName(QString::fromUtf8("pshBStudy"));
pshBStudy->setGeometry(QRect(140, 120, 161, 81));
pshBStudy->setDefault(true);
pshBSimulator = new QPushButton(centralwidget);
pshBSimulator->setObjectName(QString::fromUtf8("pshBSimulator"));
pshBSimulator->setGeometry(QRect(530, 120, 161, 81));
pshBExamCalen = new QPushButton(centralwidget);
pshBExamCalen->setObjectName(QString::fromUtf8("pshBExamCalen"));
pshBExamCalen->setGeometry(QRect(140, 260, 161, 81));
pshBReadOfDay = new QPushButton(centralwidget);
pshBReadOfDay->setObjectName(QString::fromUtf8("pshBReadOfDay"));
pshBReadOfDay->setGeometry(QRect(530, 260, 161, 81));
labelTitle = new QLabel(centralwidget);
labelTitle->setObjectName(QString::fromUtf8("labelTitle"));
labelTitle->setGeometry(QRect(200, 10, 431, 71));
QFont font;
font.setPointSize(23);
labelTitle->setFont(font);
plainTextNews = new QPlainTextEdit(centralwidget);
plainTextNews->setObjectName(QString::fromUtf8("plainTextNews"));
plainTextNews->setGeometry(QRect(610, 440, 181, 111));
plainTextNews->setReadOnly(true);
labelNews = new QLabel(centralwidget);
labelNews->setObjectName(QString::fromUtf8("labelNews"));
labelNews->setGeometry(QRect(610, 420, 81, 16));
groupBox = new QGroupBox(centralwidget);
groupBox->setObjectName(QString::fromUtf8("groupBox"));
groupBox->setGeometry(QRect(0, 460, 431, 91));
labelCollege = new QLabel(groupBox);
labelCollege->setObjectName(QString::fromUtf8("labelCollege"));
labelCollege->setGeometry(QRect(230, 50, 111, 16));
labelCourse = new QLabel(groupBox);
labelCourse->setObjectName(QString::fromUtf8("labelCourse"));
labelCourse->setGeometry(QRect(230, 30, 111, 16));
labelMemSince = new QLabel(groupBox);
labelMemSince->setObjectName(QString::fromUtf8("labelMemSince"));
labelMemSince->setGeometry(QRect(10, 50, 111, 16));
labelLoggedWith = new QLabel(groupBox);
labelLoggedWith->setObjectName(QString::fromUtf8("labelLoggedWith"));
labelLoggedWith->setGeometry(QRect(10, 30, 111, 16));
labelBP = new QLabel(groupBox);
labelBP->setObjectName(QString::fromUtf8("labelBP"));
labelBP->setGeometry(QRect(10, 70, 111, 16));
MainWindow->setCentralWidget(centralwidget);
statusbar = new QStatusBar(MainWindow);
statusbar->setObjectName(QString::fromUtf8("statusbar"));
MainWindow->setStatusBar(statusbar);
menuBar = new QMenuBar(MainWindow);
menuBar->setObjectName(QString::fromUtf8("menuBar"));
menuBar->setGeometry(QRect(0, 0, 800, 21));
menuArquivo = new QMenu(menuBar);
menuArquivo->setObjectName(QString::fromUtf8("menuArquivo"));
MainWindow->setMenuBar(menuBar);
QWidget::setTabOrder(pshBStudy, pshBSimulator);
QWidget::setTabOrder(pshBSimulator, pshBExamCalen);
QWidget::setTabOrder(pshBExamCalen, pshBReadOfDay);
QWidget::setTabOrder(pshBReadOfDay, plainTextNews);
menuBar->addAction(menuArquivo->menuAction());
menuArquivo->addAction(actionSair);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
actionAjuda->setText(QApplication::translate("MainWindow", "Sobre...", 0, QApplication::UnicodeUTF8));
actionLista_de->setText(QApplication::translate("MainWindow", "Lista de Provas", 0, QApplication::UnicodeUTF8));
actionSair->setText(QApplication::translate("MainWindow", "Sair...", 0, QApplication::UnicodeUTF8));
pshBStudy->setText(QApplication::translate("MainWindow", "Estudar!", 0, QApplication::UnicodeUTF8));
pshBSimulator->setText(QApplication::translate("MainWindow", "Simulado", 0, QApplication::UnicodeUTF8));
pshBExamCalen->setText(QApplication::translate("MainWindow", "Calend\303\241rio de Provas", 0, QApplication::UnicodeUTF8));
pshBReadOfDay->setText(QApplication::translate("MainWindow", "Leitura do Dia", 0, QApplication::UnicodeUTF8));
labelTitle->setText(QApplication::translate("MainWindow", "Escolha o que quer fazer hoje: ", 0, QApplication::UnicodeUTF8));
labelNews->setText(QApplication::translate("MainWindow", "Novidades:", 0, QApplication::UnicodeUTF8));
groupBox->setTitle(QApplication::translate("MainWindow", "Informa\303\247\303\265es", 0, QApplication::UnicodeUTF8));
labelCollege->setText(QApplication::translate("MainWindow", "Faculdade:", 0, QApplication::UnicodeUTF8));
labelCourse->setText(QApplication::translate("MainWindow", "Curso Pretendido:", 0, QApplication::UnicodeUTF8));
labelMemSince->setText(QApplication::translate("MainWindow", "Membro desde:", 0, QApplication::UnicodeUTF8));
labelLoggedWith->setText(QApplication::translate("MainWindow", "Voc\303\252 esta logado com: ", 0, QApplication::UnicodeUTF8));
labelBP->setText(QApplication::translate("MainWindow", "BP: ", 0, QApplication::UnicodeUTF8));
menuArquivo->setTitle(QApplication::translate("MainWindow", "Arquivo", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_MAINWINDOW_H
You can use the signal and slot mechanism, for that please go through the following documentation..
http://qt-project.org/doc/qt-4.8/signalsandslots.html
Now you can connect the signal of one window to the another and in the slot of the other window you show the other window and hide the previous one.
well, after some patience and study of the Qt Architecture I did it.
I just added that line in Ui_MainWindow::SetupUI(blablabla)
studyWindow = new StudyWindow(MainWindow);
QObject::connect(pshBStudy, SIGNAL(clicked()), studyWindow, SLOT(show()));
And the respective attribute to Ui_MainWindow Class. And now it's working alright.
So you have one window A which "controls" the others W1, W2, ...., Wn?
One way is to do :
Associate each of the 3 buttons Bi to their respective window Wi (like a map where a key is a button and the value the QMainWindow)
Create a custom slot in window A and connect the clicked() signals of each of the buttons to this slot.
In this slot you find which button Bi sent the signal using sender(). You find the associated window Wi and you call show(). In the meanwhile you call hide() for all other windows Wj, j!=i
All the methods cited above are either in the doc of QWidget or Qobject, so you should read it.
Related
I am using QGridLayout, the first row has a QLabel which is used to show an icon set to 32x32 pixels. The next row has two QSvgWidgets, each of these is 16x14.
My code:
QGridLayout* pgrdloStatus(new QGridLayout);
if ( mplblStsIcon == nullptr )
{
mplblStsIcon = new QLabel();
}
if ( mpsvgRxIcon == nullptr )
{
mpsvgRxIcon = new QSvgWidget(":/SVG_LED");
mpsvgRxIcon->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
mpsvgRxIcon->setFixedSize(TraineeMonitor::mscuintCommsIconWidth,
TraineeMonitor::mscuintCommsIconHeight);
}
if ( mpsvgTxIcon == nullptr )
{
mpsvgTxIcon = new QSvgWidget(":/SVG_LED");
mpsvgTxIcon->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
mpsvgTxIcon->setFixedSize(TraineeMonitor::mscuintCommsIconWidth,
TraineeMonitor::mscuintCommsIconHeight);
}
const QString cstrToolTip(QString(
" %1: %2\r\n%3: %4")
.arg(tr("Hostname:")).arg(mstrHostname)
.arg(tr("MAC address:")).arg(mstrMACaddress));
mplblStsIcon->setToolTip(cstrToolTip);
pgrdloStatus->addWidget(mplblStsIcon, 0, 0, 1, 2, Qt::AlignHCenter);
pgrdloStatus->addWidget(mpsvgRxIcon, 1, 0, Qt::AlignLeft);
pgrdloStatus->addWidget(mpsvgTxIcon, 1, 1, Qt::AlignRight);
pgrdloStatus->setMargin(0);
pgrdloStatus->setSpacing(0);
return pgrdloStatus;
The result:
What I actually want is:
I create this Example and add Items From the Designer to show you why you see that distance between icons.
I create GridLayout and put 2 labels and set 2 LED SVG image
this is what actually you do too :
But For Fixing this issue you should check this property :
which means this : label->setScaledContents(true);
Which means that your icons match to labels.
For removing margins of GridLay out you can also do this :
This is its code:
#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H
#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public:
QWidget *centralwidget;
QGridLayout *gridLayout;
QLabel *label;
QLabel *label_2;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(207, 109);
centralwidget = new QWidget(MainWindow);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
gridLayout = new QGridLayout(centralwidget);
gridLayout->setSpacing(0);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
gridLayout->setContentsMargins(0, 0, 0, 0);
label = new QLabel(centralwidget);
label->setObjectName(QString::fromUtf8("label"));
label->setPixmap(QPixmap(QString::fromUtf8(":/icons/led-square-red.svg")));
label->setScaledContents(true);
gridLayout->addWidget(label, 0, 0, 1, 1);
label_2 = new QLabel(centralwidget);
label_2->setObjectName(QString::fromUtf8("label_2"));
label_2->setPixmap(QPixmap(QString::fromUtf8(":/icons/led-square-red.svg")));
label_2->setScaledContents(true);
gridLayout->addWidget(label_2, 0, 1, 1, 1);
MainWindow->setCentralWidget(centralwidget);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QCoreApplication::translate("MainWindow", "MainWindow", nullptr));
label->setText(QString());
label_2->setText(QString());
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_MAINWINDOW_H
To what I've done: I converted a XML file from Qt Designer via the uic tool to a header file and tried to open and run that in VS2019 and VS2017.
The problem:
VS2019/2017 gives me errors (E0020, E1696, maybe so others too) and I think VS can't import the Qt libraries, even though I installed
"Qt Visual Studio Tools" and I don't know how to fix that now.
The errors look something like this:
E1696: the file "source" can't be opened: "QtWidgets/QFrame" (and other QtWidget, QtCore, and QtGui libraries)
E0020: the identifier "QtPushButton" is not defined (and other widgets like "QtLabel", "QtScrollbar", etc)
The second question would be: When the first one is fixed, how do I run the code, that creates the window from that header file? In Qt Designer I only had to press the "run" button and it ran the main function. Does it work the same way with the created header file and the main from Qt Designer?
header file (created via uic):
/*******************************************************************************
** Created by: Qt User Interface Compiler version 5.13.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef PATCHBOT_GUI_H
#define PATCHBOT_GUI_H
#include <QtCore/QVariant>
#include <QtGui/QIcon>
#include <QtWidgets/QApplication>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QFrame>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QScrollBar>
#include <QtWidgets/QStatusBar>
#include <QtWidgets/QTextEdit>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public:
QWidget *centralwidget;
QGridLayout *gridLayout;
QFrame *selectColonyFrame;
QPushButton *selectColonyButton;
QFrame *currentColonyFrame;
QLabel *currentColonyLabel;
QFrame *missionControlsFrame;
QVBoxLayout *verticalLayout;
QLabel *misisonControlsLabel;
QGridLayout *missionControlsGridLayout;
QPushButton *startButton;
QPushButton *abortButton;
QPushButton *singleStepButton;
QPushButton *autoButton;
QPushButton *pauseButton;
QFrame *botControlsFrame;
QGridLayout *gridLayout_2;
QGridLayout *botControlsGridLayout;
QPushButton *downButton;
QPushButton *upButton;
QPushButton *waitButton;
QPushButton *leftButton;
QPushButton *deleteButton;
QPushButton *rightButton;
QLabel *botControlsLabel;
QComboBox *repeatDropdown;
QFrame *frame_6;
QFrame *botCommandFrame;
QTextEdit *botCommandTextEdit;
QFrame *mapFrame;
QGridLayout *gridLayout_6;
QLabel *label;
QScrollBar *verticalScrollBar;
QScrollBar *horizontalScrollBar;
QMenuBar *menubar;
QStatusBar *statusbar;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(819, 634);
MainWindow->setMinimumSize(QSize(580, 400));
centralwidget = new QWidget(MainWindow);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
gridLayout = new QGridLayout(centralwidget);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
gridLayout->setVerticalSpacing(6);
gridLayout->setContentsMargins(-1, 0, -1, 0);
selectColonyFrame = new QFrame(centralwidget);
selectColonyFrame->setObjectName(QString::fromUtf8("selectColonyFrame"));
selectColonyFrame->setMinimumSize(QSize(150, 40));
selectColonyFrame->setLayoutDirection(Qt::RightToLeft);
selectColonyFrame->setFrameShape(QFrame::StyledPanel);
selectColonyFrame->setFrameShadow(QFrame::Raised);
selectColonyButton = new QPushButton(selectColonyFrame);
selectColonyButton->setObjectName(QString::fromUtf8("selectColonyButton"));
selectColonyButton->setGeometry(QRect(80, 0, 150, 40));
selectColonyButton->setMinimumSize(QSize(150, 40));
selectColonyButton->setMaximumSize(QSize(150, 50));
QFont font;
font.setPointSize(11);
font.setBold(true);
font.setWeight(75);
selectColonyButton->setFont(font);
gridLayout->addWidget(selectColonyFrame, 0, 1, 1, 1);
currentColonyFrame = new QFrame(centralwidget);
currentColonyFrame->setObjectName(QString::fromUtf8("currentColonyFrame"));
QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(currentColonyFrame->sizePolicy().hasHeightForWidth());
currentColonyFrame->setSizePolicy(sizePolicy);
currentColonyFrame->setMinimumSize(QSize(0, 25));
currentColonyFrame->setFrameShape(QFrame::StyledPanel);
currentColonyFrame->setFrameShadow(QFrame::Raised);
currentColonyLabel = new QLabel(currentColonyFrame);
currentColonyLabel->setObjectName(QString::fromUtf8("currentColonyLabel"));
currentColonyLabel->setGeometry(QRect(10, 10, 301, 16));
currentColonyLabel->setMinimumSize(QSize(220, 15));
currentColonyLabel->setMaximumSize(QSize(460, 25));
QFont font1;
font1.setPointSize(10);
currentColonyLabel->setFont(font1);
gridLayout->addWidget(currentColonyFrame, 0, 0, 1, 1);
missionControlsFrame = new QFrame(centralwidget);
missionControlsFrame->setObjectName(QString::fromUtf8("missionControlsFrame"));
QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Preferred);
sizePolicy1.setHorizontalStretch(8);
sizePolicy1.setVerticalStretch(8);
sizePolicy1.setHeightForWidth(missionControlsFrame->sizePolicy().hasHeightForWidth());
missionControlsFrame->setSizePolicy(sizePolicy1);
missionControlsFrame->setMaximumSize(QSize(300, 180));
missionControlsFrame->setFrameShape(QFrame::WinPanel);
missionControlsFrame->setFrameShadow(QFrame::Raised);
verticalLayout = new QVBoxLayout(missionControlsFrame);
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
misisonControlsLabel = new QLabel(missionControlsFrame);
misisonControlsLabel->setObjectName(QString::fromUtf8("misisonControlsLabel"));
QFont font2;
font2.setPointSize(11);
misisonControlsLabel->setFont(font2);
misisonControlsLabel->setAlignment(Qt::AlignCenter);
verticalLayout->addWidget(misisonControlsLabel);
missionControlsGridLayout = new QGridLayout();
missionControlsGridLayout->setObjectName(QString::fromUtf8("missionControlsGridLayout"));
missionControlsGridLayout->setHorizontalSpacing(20);
missionControlsGridLayout->setVerticalSpacing(10);
missionControlsGridLayout->setContentsMargins(15, 20, 15, 0);
startButton = new QPushButton(missionControlsFrame);
startButton->setObjectName(QString::fromUtf8("startButton"));
startButton->setMinimumSize(QSize(80, 30));
startButton->setMaximumSize(QSize(130, 50));
QFont font3;
font3.setPointSize(12);
startButton->setFont(font3);
missionControlsGridLayout->addWidget(startButton, 0, 0, 1, 1);
abortButton = new QPushButton(missionControlsFrame);
abortButton->setObjectName(QString::fromUtf8("abortButton"));
abortButton->setMinimumSize(QSize(80, 30));
abortButton->setMaximumSize(QSize(130, 50));
abortButton->setFont(font3);
abortButton->setLayoutDirection(Qt::LeftToRight);
abortButton->setAutoDefault(false);
abortButton->setFlat(false);
missionControlsGridLayout->addWidget(abortButton, 0, 1, 1, 1);
singleStepButton = new QPushButton(missionControlsFrame);
singleStepButton->setObjectName(QString::fromUtf8("singleStepButton"));
singleStepButton->setMinimumSize(QSize(80, 30));
singleStepButton->setMaximumSize(QSize(130, 50));
singleStepButton->setFont(font3);
missionControlsGridLayout->addWidget(singleStepButton, 1, 0, 1, 1);
autoButton = new QPushButton(missionControlsFrame);
autoButton->setObjectName(QString::fromUtf8("autoButton"));
autoButton->setMinimumSize(QSize(80, 30));
autoButton->setMaximumSize(QSize(130, 50));
autoButton->setFont(font3);
autoButton->setLayoutDirection(Qt::LeftToRight);
autoButton->setAutoDefault(false);
autoButton->setFlat(false);
missionControlsGridLayout->addWidget(autoButton, 1, 1, 1, 1);
pauseButton = new QPushButton(missionControlsFrame);
pauseButton->setObjectName(QString::fromUtf8("pauseButton"));
pauseButton->setMinimumSize(QSize(80, 30));
pauseButton->setMaximumSize(QSize(130, 50));
pauseButton->setFont(font3);
pauseButton->setLayoutDirection(Qt::LeftToRight);
pauseButton->setAutoDefault(false);
pauseButton->setFlat(false);
missionControlsGridLayout->addWidget(pauseButton, 2, 1, 1, 1);
verticalLayout->addLayout(missionControlsGridLayout);
gridLayout->addWidget(missionControlsFrame, 3, 1, 1, 1);
botControlsFrame = new QFrame(centralwidget);
botControlsFrame->setObjectName(QString::fromUtf8("botControlsFrame"));
QSizePolicy sizePolicy2(QSizePolicy::Preferred, QSizePolicy::Preferred);
sizePolicy2.setHorizontalStretch(4);
sizePolicy2.setVerticalStretch(4);
sizePolicy2.setHeightForWidth(botControlsFrame->sizePolicy().hasHeightForWidth());
botControlsFrame->setSizePolicy(sizePolicy2);
botControlsFrame->setMinimumSize(QSize(160, 120));
botControlsFrame->setMaximumSize(QSize(320, 240));
botControlsFrame->setFrameShape(QFrame::WinPanel);
botControlsFrame->setFrameShadow(QFrame::Raised);
gridLayout_2 = new QGridLayout(botControlsFrame);
gridLayout_2->setObjectName(QString::fromUtf8("gridLayout_2"));
botControlsGridLayout = new QGridLayout();
botControlsGridLayout->setObjectName(QString::fromUtf8("botControlsGridLayout"));
botControlsGridLayout->setSizeConstraint(QLayout::SetMinimumSize);
downButton = new QPushButton(botControlsFrame);
downButton->setObjectName(QString::fromUtf8("downButton"));
downButton->setMinimumSize(QSize(30, 30));
downButton->setMaximumSize(QSize(50, 50));
downButton->setLayoutDirection(Qt::LeftToRight);
QIcon icon;
icon.addFile(QString::fromUtf8(":/grafics/grafics/pfeile/pfeil_unten.tga"), QSize(), QIcon::Normal, QIcon::Off);
downButton->setIcon(icon);
downButton->setIconSize(QSize(50, 50));
botControlsGridLayout->addWidget(downButton, 2, 1, 1, 1);
upButton = new QPushButton(botControlsFrame);
upButton->setObjectName(QString::fromUtf8("upButton"));
upButton->setMinimumSize(QSize(30, 30));
upButton->setMaximumSize(QSize(50, 50));
upButton->setSizeIncrement(QSize(0, 0));
QIcon icon1;
icon1.addFile(QString::fromUtf8(":/grafics/grafics/pfeile/pfeil_oben.tga"), QSize(), QIcon::Normal, QIcon::Off);
upButton->setIcon(icon1);
upButton->setIconSize(QSize(50, 50));
botControlsGridLayout->addWidget(upButton, 0, 1, 1, 1);
waitButton = new QPushButton(botControlsFrame);
waitButton->setObjectName(QString::fromUtf8("waitButton"));
waitButton->setMinimumSize(QSize(30, 30));
waitButton->setMaximumSize(QSize(50, 50));
QFont font4;
font4.setFamily(QString::fromUtf8("MS Shell Dlg 2"));
font4.setPointSize(15);
waitButton->setFont(font4);
waitButton->setContextMenuPolicy(Qt::DefaultContextMenu);
QIcon icon2;
QString iconThemeName = QString::fromUtf8("◀");
if (QIcon::hasThemeIcon(iconThemeName)) {
icon2 = QIcon::fromTheme(iconThemeName);
} else {
icon2.addFile(QString::fromUtf8("."), QSize(), QIcon::Normal, QIcon::Off);
}
waitButton->setIcon(icon2);
botControlsGridLayout->addWidget(waitButton, 1, 1, 1, 1);
leftButton = new QPushButton(botControlsFrame);
leftButton->setObjectName(QString::fromUtf8("leftButton"));
leftButton->setMinimumSize(QSize(30, 30));
leftButton->setMaximumSize(QSize(50, 50));
QIcon icon3;
icon3.addFile(QString::fromUtf8(":/grafics/grafics/pfeile/pfeil_links.tga"), QSize(), QIcon::Normal, QIcon::Off);
leftButton->setIcon(icon3);
leftButton->setIconSize(QSize(50, 50));
botControlsGridLayout->addWidget(leftButton, 1, 0, 1, 1);
deleteButton = new QPushButton(botControlsFrame);
deleteButton->setObjectName(QString::fromUtf8("deleteButton"));
deleteButton->setMinimumSize(QSize(30, 30));
deleteButton->setMaximumSize(QSize(50, 50));
QFont font5;
font5.setPointSize(15);
deleteButton->setFont(font5);
botControlsGridLayout->addWidget(deleteButton, 0, 2, 1, 1);
rightButton = new QPushButton(botControlsFrame);
rightButton->setObjectName(QString::fromUtf8("rightButton"));
rightButton->setMinimumSize(QSize(30, 30));
rightButton->setMaximumSize(QSize(50, 50));
rightButton->setSizeIncrement(QSize(0, 0));
QIcon icon4;
icon4.addFile(QString::fromUtf8(":/grafics/grafics/pfeile/pfeil_rechts.tga"), QSize(), QIcon::Normal, QIcon::Off);
rightButton->setIcon(icon4);
rightButton->setIconSize(QSize(50, 50));
botControlsGridLayout->addWidget(rightButton, 1, 2, 1, 1);
gridLayout_2->addLayout(botControlsGridLayout, 1, 0, 3, 1);
botControlsLabel = new QLabel(botControlsFrame);
botControlsLabel->setObjectName(QString::fromUtf8("botControlsLabel"));
botControlsLabel->setFont(font2);
botControlsLabel->setAlignment(Qt::AlignCenter);
gridLayout_2->addWidget(botControlsLabel, 0, 0, 1, 2);
repeatDropdown = new QComboBox(botControlsFrame);
repeatDropdown->addItem(QString());
repeatDropdown->addItem(QString());
repeatDropdown->addItem(QString());
repeatDropdown->addItem(QString());
repeatDropdown->addItem(QString());
repeatDropdown->setObjectName(QString::fromUtf8("repeatDropdown"));
repeatDropdown->setMinimumSize(QSize(80, 30));
repeatDropdown->setMaximumSize(QSize(130, 50));
QFont font6;
font6.setPointSize(15);
font6.setBold(true);
font6.setItalic(false);
font6.setWeight(75);
repeatDropdown->setFont(font6);
repeatDropdown->setFocusPolicy(Qt::WheelFocus);
repeatDropdown->setLayoutDirection(Qt::LeftToRight);
repeatDropdown->setInsertPolicy(QComboBox::NoInsert);
repeatDropdown->setFrame(true);
gridLayout_2->addWidget(repeatDropdown, 1, 1, 1, 1);
frame_6 = new QFrame(botControlsFrame);
frame_6->setObjectName(QString::fromUtf8("frame_6"));
frame_6->setFrameShape(QFrame::StyledPanel);
frame_6->setFrameShadow(QFrame::Raised);
gridLayout_2->addWidget(frame_6, 2, 1, 1, 1);
botCommandFrame = new QFrame(botControlsFrame);
botCommandFrame->setObjectName(QString::fromUtf8("botCommandFrame"));
botCommandFrame->setMinimumSize(QSize(100, 80));
botCommandFrame->setMaximumSize(QSize(130, 16777215));
botCommandFrame->setFrameShape(QFrame::StyledPanel);
botCommandFrame->setFrameShadow(QFrame::Raised);
botCommandTextEdit = new QTextEdit(botCommandFrame);
botCommandTextEdit->setObjectName(QString::fromUtf8("botCommandTextEdit"));
botCommandTextEdit->setGeometry(QRect(0, 16, 108, 50));
QSizePolicy sizePolicy3(QSizePolicy::Expanding, QSizePolicy::Expanding);
sizePolicy3.setHorizontalStretch(130);
sizePolicy3.setVerticalStretch(50);
sizePolicy3.setHeightForWidth(botCommandTextEdit->sizePolicy().hasHeightForWidth());
botCommandTextEdit->setSizePolicy(sizePolicy3);
botCommandTextEdit->setMinimumSize(QSize(80, 30));
botCommandTextEdit->setMaximumSize(QSize(130, 50));
botCommandTextEdit->setFont(font5);
botCommandTextEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
botCommandTextEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
botCommandTextEdit->setLineWrapMode(QTextEdit::NoWrap);
botCommandTextEdit->setReadOnly(true);
gridLayout_2->addWidget(botCommandFrame, 3, 1, 1, 1);
gridLayout_2->setRowStretch(1, 2);
gridLayout_2->setRowStretch(2, 1);
gridLayout_2->setRowStretch(3, 1);
gridLayout->addWidget(botControlsFrame, 1, 1, 2, 1);
mapFrame = new QFrame(centralwidget);
mapFrame->setObjectName(QString::fromUtf8("mapFrame"));
QSizePolicy sizePolicy4(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
sizePolicy4.setHorizontalStretch(0);
sizePolicy4.setVerticalStretch(0);
sizePolicy4.setHeightForWidth(mapFrame->sizePolicy().hasHeightForWidth());
mapFrame->setSizePolicy(sizePolicy4);
mapFrame->setMinimumSize(QSize(120, 120));
mapFrame->setFrameShape(QFrame::StyledPanel);
mapFrame->setFrameShadow(QFrame::Raised);
gridLayout_6 = new QGridLayout(mapFrame);
gridLayout_6->setSpacing(0);
gridLayout_6->setObjectName(QString::fromUtf8("gridLayout_6"));
label = new QLabel(mapFrame);
label->setObjectName(QString::fromUtf8("label"));
sizePolicy4.setHeightForWidth(label->sizePolicy().hasHeightForWidth());
label->setSizePolicy(sizePolicy4);
label->setMinimumSize(QSize(0, 0));
label->setFrameShape(QFrame::Box);
label->setAlignment(Qt::AlignCenter);
gridLayout_6->addWidget(label, 0, 0, 1, 1);
verticalScrollBar = new QScrollBar(mapFrame);
verticalScrollBar->setObjectName(QString::fromUtf8("verticalScrollBar"));
verticalScrollBar->setOrientation(Qt::Vertical);
gridLayout_6->addWidget(verticalScrollBar, 0, 1, 1, 1);
horizontalScrollBar = new QScrollBar(mapFrame);
horizontalScrollBar->setObjectName(QString::fromUtf8("horizontalScrollBar"));
QSizePolicy sizePolicy5(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
sizePolicy5.setHorizontalStretch(0);
sizePolicy5.setVerticalStretch(0);
sizePolicy5.setHeightForWidth(horizontalScrollBar->sizePolicy().hasHeightForWidth());
horizontalScrollBar->setSizePolicy(sizePolicy5);
horizontalScrollBar->setOrientation(Qt::Horizontal);
gridLayout_6->addWidget(horizontalScrollBar, 1, 0, 1, 1);
gridLayout->addWidget(mapFrame, 1, 0, 3, 1);
gridLayout->setRowStretch(0, 1);
gridLayout->setRowStretch(1, 4);
gridLayout->setRowStretch(2, 4);
gridLayout->setColumnStretch(0, 2);
gridLayout->setColumnMinimumWidth(0, 1);
gridLayout->setColumnMinimumWidth(1, 1);
gridLayout->setRowMinimumHeight(0, 1);
gridLayout->setRowMinimumHeight(1, 1);
gridLayout->setRowMinimumHeight(2, 10);
gridLayout->setRowMinimumHeight(3, 1);
MainWindow->setCentralWidget(centralwidget);
menubar = new QMenuBar(MainWindow);
menubar->setObjectName(QString::fromUtf8("menubar"));
menubar->setGeometry(QRect(0, 0, 819, 20));
MainWindow->setMenuBar(menubar);
statusbar = new QStatusBar(MainWindow);
statusbar->setObjectName(QString::fromUtf8("statusbar"));
MainWindow->setStatusBar(statusbar);
retranslateUi(MainWindow);
abortButton->setDefault(false);
autoButton->setDefault(false);
pauseButton->setDefault(false);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QCoreApplication::translate("MainWindow", "MainWindow", nullptr));
selectColonyButton->setText(QCoreApplication::translate("MainWindow", "Andere Kolonie ...", nullptr));
currentColonyLabel->setText(QCoreApplication::translate("MainWindow", "Aktuelle Kolonie: Lithium-Stollen 13-A", nullptr));
misisonControlsLabel->setText(QCoreApplication::translate("MainWindow", "Missionsablauf", nullptr));
startButton->setText(QCoreApplication::translate("MainWindow", "Start", nullptr));
abortButton->setText(QCoreApplication::translate("MainWindow", "Abbruch", nullptr));
singleStepButton->setText(QCoreApplication::translate("MainWindow", "Einzelschritt", nullptr));
autoButton->setText(QCoreApplication::translate("MainWindow", "Automatik", nullptr));
pauseButton->setText(QCoreApplication::translate("MainWindow", "Anhalten", nullptr));
downButton->setText(QString());
upButton->setText(QString());
waitButton->setText(QCoreApplication::translate("MainWindow", "W", nullptr));
leftButton->setText(QString());
deleteButton->setText(QCoreApplication::translate("MainWindow", "<", nullptr));
rightButton->setText(QString());
botControlsLabel->setText(QCoreApplication::translate("MainWindow", "Programmieren", nullptr));
repeatDropdown->setItemText(0, QCoreApplication::translate("MainWindow", "1", nullptr));
repeatDropdown->setItemText(1, QCoreApplication::translate("MainWindow", "2", nullptr));
repeatDropdown->setItemText(2, QCoreApplication::translate("MainWindow", "3", nullptr));
repeatDropdown->setItemText(3, QCoreApplication::translate("MainWindow", "4", nullptr));
repeatDropdown->setItemText(4, QCoreApplication::translate("MainWindow", "5", nullptr));
repeatDropdown->setCurrentText(QCoreApplication::translate("MainWindow", "1", nullptr));
botCommandTextEdit->setPlaceholderText(QCoreApplication::translate("MainWindow", "Textfeld", nullptr));
label->setText(QCoreApplication::translate("MainWindow", "Umgebungskarte", nullptr));
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // PATCHBOT_GUI_H
main file (from Qt Designer):
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
other files (from Qt Designer):
mainwindow.cpp (to customize my buttons):
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QMessageBox"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_upButton_clicked()
{
QMessageBox::information(this, "button", "up");
}
void MainWindow::on_rightButton_clicked()
{
QMessageBox::information(this, "button", "right");
}
void MainWindow::on_downButton_clicked()
{
QMessageBox::information(this, "button", "down");
}
void MainWindow::on_leftButton_clicked()
{
QMessageBox::information(this, "button", "left");
}
void MainWindow::on_waitButton_clicked()
{
QMessageBox::information(this, "button", "wait");
}
void MainWindow::on_deleteButton_clicked()
{
QMessageBox::information(this, "button", "delete");
}
void MainWindow::on_selectColonyButton_clicked()
{
QMessageBox::information(this, "button", ui->selectColonyButton->text());
}
void MainWindow::on_startButton_clicked()
{
QMessageBox::information(this, "button", ui->startButton->text());
}
void MainWindow::on_abortButton_clicked()
{
QMessageBox::information(this, "button", ui->abortButton->text());
}
void MainWindow::on_singleStepButton_clicked()
{
QMessageBox::information(this, "button", ui->singleStepButton->text());
}
void MainWindow::on_autoButton_clicked()
{
QMessageBox::information(this, "button", ui->autoButton->text());
}
void MainWindow::on_pauseButton_clicked()
{
QMessageBox::information(this, "button", ui->pauseButton->text());
}
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void on_upButton_clicked();
void on_rightButton_clicked();
void on_downButton_clicked();
void on_leftButton_clicked();
void on_waitButton_clicked();
void on_deleteButton_clicked();
void on_selectColonyButton_clicked();
void on_startButton_clicked();
void on_abortButton_clicked();
void on_singleStepButton_clicked();
void on_autoButton_clicked();
void on_pauseButton_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
If further information is needed, I'd be happy to help.
What I want to do is that it give me a list with all .cpp files in the Directory and the Subdirectories. Problem it.HasNext stay on false and also it.filePath stay empty.
main.cpp
#include "QtSignal_Slot.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QtSignal_Slot w;
w.show();
return a.exec();
}
ui_QtSignal_Slot.h
#ifndef UI_QTSIGNAL_SLOT_H
#define UI_QTSIGNAL_SLOT_H
#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QSpacerItem>
#include <QtWidgets/QStatusBar>
#include <QtWidgets/QTextEdit>
#include <QtWidgets/QToolBar>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_QtSignal_SlotClass
{
public:
QWidget *centralWidget;
QGridLayout *gridLayout;
QPushButton *ButtonStart;
QSpacerItem *horizontalSpacer_2;
QSpacerItem *horizontalSpacer_4;
QTextEdit *textEdit;
QSpacerItem *verticalSpacer_2;
QSpacerItem *verticalSpacer_3;
QSpacerItem *horizontalSpacer;
QSpacerItem *horizontalSpacer_3;
QLineEdit *PathEdit;
QMenuBar *menuBar;
QToolBar *mainToolBar;
QStatusBar *statusBar;
void setupUi(QMainWindow *QtSignal_SlotClass)
{
if (QtSignal_SlotClass->objectName().isEmpty())
QtSignal_SlotClass->setObjectName(QStringLiteral("QtSignal_SlotClass"));
QtSignal_SlotClass->setEnabled(true);
QtSignal_SlotClass->resize(380, 250);
QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(QtSignal_SlotClass->sizePolicy().hasHeightForWidth());
QtSignal_SlotClass->setSizePolicy(sizePolicy);
QtSignal_SlotClass->setMinimumSize(QSize(380, 250));
QtSignal_SlotClass->setMaximumSize(QSize(700, 300));
QtSignal_SlotClass->setSizeIncrement(QSize(400, 250));
QtSignal_SlotClass->setBaseSize(QSize(200, 250));
centralWidget = new QWidget(QtSignal_SlotClass);
centralWidget->setObjectName(QStringLiteral("centralWidget"));
gridLayout = new QGridLayout(centralWidget);
gridLayout->setSpacing(6);
gridLayout->setContentsMargins(11, 11, 11, 11);
gridLayout->setObjectName(QStringLiteral("gridLayout"));
ButtonStart = new QPushButton(centralWidget);
ButtonStart->setObjectName(QStringLiteral("ButtonStart"));
ButtonStart->setStyleSheet(QStringLiteral("background-color: rgb(200,200,255); color: rgb(0,0,0);"));
gridLayout->addWidget(ButtonStart, 7, 1, 1, 1);
horizontalSpacer_2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
gridLayout->addItem(horizontalSpacer_2, 7, 2, 1, 1);
horizontalSpacer_4 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
gridLayout->addItem(horizontalSpacer_4, 0, 2, 1, 1);
textEdit = new QTextEdit(centralWidget);
textEdit->setObjectName(QStringLiteral("textEdit"));
textEdit->setStyleSheet(QStringLiteral("color: rgb(0,0,0);"));
gridLayout->addWidget(textEdit, 3, 1, 1, 1);
verticalSpacer_2 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
gridLayout->addItem(verticalSpacer_2, 1, 1, 1, 1);
verticalSpacer_3 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
gridLayout->addItem(verticalSpacer_3, 2, 1, 1, 1);
horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
gridLayout->addItem(horizontalSpacer, 7, 0, 1, 1);
horizontalSpacer_3 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
gridLayout->addItem(horizontalSpacer_3, 0, 0, 1, 1);
PathEdit = new QLineEdit(centralWidget);
PathEdit->setObjectName(QStringLiteral("PathEdit"));
QSizePolicy sizePolicy1(QSizePolicy::Expanding, QSizePolicy::Preferred);
sizePolicy1.setHorizontalStretch(0);
sizePolicy1.setVerticalStretch(0);
sizePolicy1.setHeightForWidth(PathEdit->sizePolicy().hasHeightForWidth());
PathEdit->setSizePolicy(sizePolicy1);
PathEdit->setMinimumSize(QSize(200, 30));
PathEdit->setStyleSheet(QStringLiteral("background-color: rgb(240,240,240); color: rgb(0,0,0);"));
gridLayout->addWidget(PathEdit, 0, 1, 1, 1);
QtSignal_SlotClass->setCentralWidget(centralWidget);
menuBar = new QMenuBar(QtSignal_SlotClass);
menuBar->setObjectName(QStringLiteral("menuBar"));
menuBar->setGeometry(QRect(0, 0, 380, 21));
QtSignal_SlotClass->setMenuBar(menuBar);
mainToolBar = new QToolBar(QtSignal_SlotClass);
mainToolBar->setObjectName(QStringLiteral("mainToolBar"));
QtSignal_SlotClass->addToolBar(Qt::TopToolBarArea, mainToolBar);
statusBar = new QStatusBar(QtSignal_SlotClass);
statusBar->setObjectName(QStringLiteral("statusBar"));
QtSignal_SlotClass->setStatusBar(statusBar);
retranslateUi(QtSignal_SlotClass);
QMetaObject::connectSlotsByName(QtSignal_SlotClass);
} // setupUi
void retranslateUi(QMainWindow *QtSignal_SlotClass)
{
QtSignal_SlotClass->setWindowTitle(QApplication::translate("QtSignal_SlotClass", "QtSignal_Slot", Q_NULLPTR));
ButtonStart->setText(QApplication::translate("QtSignal_SlotClass", "Generate graphicfile", Q_NULLPTR));
PathEdit->setText(QString());
} // retranslateUi
};
namespace Ui {
class QtSignal_SlotClass: public Ui_QtSignal_SlotClass {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_QTSIGNAL_SLOT_H
QtSignal_Slot.h
#pragma once
#include <QtWidgets/QMainWindow>
#include "ui_QtSignal_Slot.h"
class QtSignal_Slot : public QMainWindow
{
Q_OBJECT
public:
QString m_Path;
QtSignal_Slot(QWidget *parent = Q_NULLPTR);
public slots:
void m_StartButtonpressed();
private:
Ui::QtSignal_SlotClass ui;
};
QtSolts_Signel.cpp
#include "QtSignal_Slot.h"
#include <ui_QtSignal_Slot.h>
#include <QDirIterator>
#include <QDebug>
QtSignal_Slot::QtSignal_Slot(QWidget *parent) : QMainWindow(nullptr)
{
ui.setupUi(this);
connect(ui.ButtonStart, SIGNAL(clicked()), this, SLOT(m_StartButtonpressed()));
}
void QtSignal_Slot::m_StartButton()
{
m_Path = (ui.PathEdit->text());
QDirIterator it(m_Path, QStringList() << "*.cpp" , QDir::Files, QDirIterator::Subdirectories);
do
{
qDebug() << it.next();
} while (it.hasNext());
qDebug() << "This, show in the Output";
QString Buffer = QString("%1").arg(QString::number(it.hasNext()));
ui.textEdit->setText(Buffer +"->" + it.filePath() + "<-" + m_Path);
}
The output in the textEdit is:
"0-> <-(correct path i but i as input)"
and output in the debug-output is:
" ' ' , This, show in the Output"
The code is updated, but the problem stays.
Example
Here is an example of how to make the slot work:
MainWindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class QLineEdit;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
private:
QLineEdit *m_pathEdit;
QLineEdit *m_textEdit;
private slots:
void onButtonClicked();
};
#endif // MAINWINDOW_H
MainWindow.cpp
#include "MainWindow.h"
#include <QDirIterator>
#include <QBoxLayout>
#include <QPushButton>
#include <QLineEdit>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
m_pathEdit(new QLineEdit(this)),
m_textEdit(new QLineEdit(this))
{
auto *widget = new QWidget(this);
auto *layoutMain = new QVBoxLayout(widget);
auto *button = new QPushButton(tr("Click me"), this);
layoutMain->addWidget(m_pathEdit);
layoutMain->addWidget(m_textEdit);
layoutMain->addWidget(button);
setCentralWidget(widget);
connect(button, &QPushButton::clicked, this, &MainWindow::onButtonClicked);
}
void MainWindow::onButtonClicked()
{
const QString &path(m_pathEdit->text());
QDirIterator it(path, QStringList() << "*.cpp" , QDir::Files, QDirIterator::Subdirectories);
do
{
qDebug() << it.next();
} while (it.hasNext());
qDebug() << "This, show in the Output";
QString buffer(QString("%1").arg(QString::number(it.hasNext())));
m_textEdit->setText(buffer +"->" + it.filePath() + "<-" + path);
}
Result
For the following input (entered in m_pathEdit, the upper QLineEdit):
/Users/Michael Scopchanov/Desktop/untitled9/
the result in the console is:
"/Users/Michael Scopchanov/Desktop/untitled9/main.cpp"
"/Users/Michael Scopchanov/Desktop/untitled9/MainWindow.cpp"
"/Users/Michael Scopchanov/Desktop/untitled9/MyLabel.cpp"
This, show in the Output
and the text of m_textEdit is set to:
0->/Users/Michael Scopchanov/Desktop/untitled9/MyLabel.cpp<-/Users/Michael Scopchanov/Desktop/untitled9/
As mentioned above my task is to change the code of an existing visual studio project that uses QT 5.7.
The student who has worked on it before me built his project with cmake with which I am completely unfamiliar, while absolutely having no time to get into, unfortunately.
My first attempt is to set up a new VS-project into which I paste all source files and QT-files necessary.
This has resulted in several problems, one of which was that I had to delete, save and rewrite Q_OBJECT in all Q-Classes.
This tells me that the actual workflow is corrupting the project right from the beginning.
With regards to this, my predecessor used QMetaObject::connectSlotsByName to connect signals and slots of Gui-Objects like Buttons. When debugging I get
QMetaObject::connectSlotsByName: No matching signal for on_[some Gui Obejct]_clicked()
for all of the existing QWidget-Childs in the GUI.
This seems strange, because the signals of such buttons and so on, have to exist in moc-code (the corresponding slots exist of course), correct?
There are a decent amount of Gui-elements existing in the project, so I prefer to not use connect for every single one of them.
Questions:
1.) Is there a recommended workflow, that will enable one to shoot oneself in the foot less often?
2.) In order to enable Qt's Meta-Object-Compiler to create ui_*.h's and moc_*.cpp's it needs *.ui's, *.qrc's, and potential resource files, correct?
3.) To what extent is it possible that the fact that the project was originally built with cmake affects Qt-meta compiling?
Thank you very much in advance
Edit:
Additional information and code sample of the QMainWindow-Class Navigation_Gui.
I added the connect line, that produces an excess violation, which I think should not be produced.
Navigation_Gui::Navigation_Gui(QWidget *parent)
: QWidget(parent){
this->Storage = new ThreadStorage();
this->CamPtr = new CamBar(this->Storage);
this->NavPtr = new Navigation(this->CamPtr, this->Storage);
ui.setupUi(this);
this->getRegPoints = false;
this->Storage->Log << "Main Gui initialized" << endl;
connect(this->ui.pushButton, SIGNAL(clicked()), this, SLOT(on_pushButton_clicked())); }
The header
#ifndef NAVIGATION_GUI_H
#define NAVIGATION_GUI_H
#include <QWidget>
#include "ui_navigation_gui.h"
#include <windows.h>
#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
#include "vtkMatrix4x4.h"
#include <vector>
#include "ThreadStorage.h"
class CamBar; //forward deklaration
class Navigation; //forward declaration
class ThreadStorage; //forward declaration
class Navigation_Gui : public QWidget
{
Q_OBJECT
public:
Navigation_Gui(QWidget *parent = 0);
~Navigation_Gui();
//! true if Button GetRegPoints is pressed.
bool getRegPoints;
public slots:
void on_pushButton_clicked();
private:
Ui::Navigation_GuiClass ui;
//! initial CameraPointer
CamBar* CamPtr;
//! initial NavigationPointer
Navigation* NavPtr;
//! initial LogPointer
ThreadStorage* Storage;
private slots:
// private slots for Gui events
void on_ConnectButton_clicked();
void on_RegPointButton_clicked();
//void on_TrackingButton_clicked();
void on_QuitButton_clicked();
void on_NewTrackingButton_clicked();
void on_getLocatorButton_clicked();
void on_MHHAbout_clicked();
};
#endif // NAVIGATION_GUI_H
And this is the generated Ui-header
#ifndef UI_NAVIGATION_GUI_H
#define UI_NAVIGATION_GUI_H
#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QSpacerItem>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_Navigation_GuiClass
{
public:
QGridLayout *gridLayout;
QVBoxLayout *verticalLayout;
QSpacerItem *verticalSpacer;
QPushButton *ConnectButton;
QSpacerItem *verticalSpacer_2;
QPushButton *getLocatorButton;
QSpacerItem *verticalSpacer_7;
QPushButton *RegPointButton;
QSpacerItem *verticalSpacer_3;
QPushButton *NewTrackingButton;
QSpacerItem *verticalSpacer_4;
QSpacerItem *verticalSpacer_5;
QPushButton *QuitButton;
QSpacerItem *verticalSpacer_6;
QPushButton *pushButton;
QPushButton *MHHAbout;
void setupUi(QWidget *Navigation_GuiClass)
{
if (Navigation_GuiClass->objectName().isEmpty())
Navigation_GuiClass->setObjectName(QStringLiteral("Navigation_GuiClass"));
Navigation_GuiClass->setWindowModality(Qt::WindowModal);
Navigation_GuiClass->resize(358, 500);
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(Navigation_GuiClass->sizePolicy().hasHeightForWidth());
Navigation_GuiClass->setSizePolicy(sizePolicy);
Navigation_GuiClass->setMinimumSize(QSize(358, 458));
Navigation_GuiClass->setMaximumSize(QSize(358, 500));
gridLayout = new QGridLayout(Navigation_GuiClass);
gridLayout->setSpacing(6);
gridLayout->setContentsMargins(11, 11, 11, 11);
gridLayout->setObjectName(QStringLiteral("gridLayout"));
verticalLayout = new QVBoxLayout();
verticalLayout->setSpacing(6);
verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
verticalSpacer = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
verticalLayout->addItem(verticalSpacer);
ConnectButton = new QPushButton(Navigation_GuiClass);
ConnectButton->setObjectName(QStringLiteral("ConnectButton"));
QSizePolicy sizePolicy1(QSizePolicy::Minimum, QSizePolicy::Minimum);
sizePolicy1.setHorizontalStretch(0);
sizePolicy1.setVerticalStretch(1);
sizePolicy1.setHeightForWidth(ConnectButton->sizePolicy().hasHeightForWidth());
ConnectButton->setSizePolicy(sizePolicy1);
ConnectButton->setMinimumSize(QSize(0, 68));
QFont font;
font.setPointSize(14);
ConnectButton->setFont(font);
verticalLayout->addWidget(ConnectButton);
verticalSpacer_2 = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
verticalLayout->addItem(verticalSpacer_2);
getLocatorButton = new QPushButton(Navigation_GuiClass);
getLocatorButton->setObjectName(QStringLiteral("getLocatorButton"));
sizePolicy1.setHeightForWidth(getLocatorButton->sizePolicy().hasHeightForWidth());
getLocatorButton->setSizePolicy(sizePolicy1);
getLocatorButton->setMinimumSize(QSize(0, 68));
getLocatorButton->setFont(font);
verticalLayout->addWidget(getLocatorButton);
verticalSpacer_7 = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
verticalLayout->addItem(verticalSpacer_7);
RegPointButton = new QPushButton(Navigation_GuiClass);
RegPointButton->setObjectName(QStringLiteral("RegPointButton"));
RegPointButton->setEnabled(false);
sizePolicy1.setHeightForWidth(RegPointButton->sizePolicy().hasHeightForWidth());
RegPointButton->setSizePolicy(sizePolicy1);
RegPointButton->setMinimumSize(QSize(0, 68));
RegPointButton->setFont(font);
verticalLayout->addWidget(RegPointButton);
verticalSpacer_3 = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
verticalLayout->addItem(verticalSpacer_3);
NewTrackingButton = new QPushButton(Navigation_GuiClass);
NewTrackingButton->setObjectName(QStringLiteral("NewTrackingButton"));
NewTrackingButton->setEnabled(false);
sizePolicy1.setHeightForWidth(NewTrackingButton->sizePolicy().hasHeightForWidth());
NewTrackingButton->setSizePolicy(sizePolicy1);
NewTrackingButton->setMinimumSize(QSize(0, 68));
NewTrackingButton->setFont(font);
verticalLayout->addWidget(NewTrackingButton);
verticalSpacer_4 = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
verticalLayout->addItem(verticalSpacer_4);
verticalSpacer_5 = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
verticalLayout->addItem(verticalSpacer_5);
QuitButton = new QPushButton(Navigation_GuiClass);
QuitButton->setObjectName(QStringLiteral("QuitButton"));
sizePolicy1.setHeightForWidth(QuitButton->sizePolicy().hasHeightForWidth());
QuitButton->setSizePolicy(sizePolicy1);
QuitButton->setMinimumSize(QSize(0, 68));
QuitButton->setFont(font);
verticalLayout->addWidget(QuitButton);
verticalSpacer_6 = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
verticalLayout->addItem(verticalSpacer_6);
pushButton = new QPushButton(Navigation_GuiClass);
pushButton->setObjectName(QStringLiteral("pushButton"));
verticalLayout->addWidget(pushButton);
MHHAbout = new QPushButton(Navigation_GuiClass);
MHHAbout->setObjectName(QStringLiteral("MHHAbout"));
QIcon icon;
icon.addFile(QStringLiteral(":/MainWindow/Resources/60px.png"), QSize(), QIcon::Normal, QIcon::Off);
MHHAbout->setIcon(icon);
MHHAbout->setIconSize(QSize(174, 60));
verticalLayout->addWidget(MHHAbout);
gridLayout->addLayout(verticalLayout, 0, 0, 1, 1);
retranslateUi(Navigation_GuiClass);
QMetaObject::connectSlotsByName(Navigation_GuiClass);
} // setupUi
void retranslateUi(QWidget *Navigation_GuiClass)
{
Navigation_GuiClass->setWindowTitle(QApplication::translate("Navigation_GuiClass", "Main Menu - Navigation (CamBar)", 0));
ConnectButton->setText(QApplication::translate("Navigation_GuiClass", "Connect", 0));
getLocatorButton->setText(QApplication::translate("Navigation_GuiClass", "Locator Editor", 0));
RegPointButton->setText(QApplication::translate("Navigation_GuiClass", "Get Registration Points", 0));
NewTrackingButton->setText(QApplication::translate("Navigation_GuiClass", "Tracking", 0));
QuitButton->setText(QApplication::translate("Navigation_GuiClass", "Quit", 0));
pushButton->setText(QApplication::translate("Navigation_GuiClass", "PushButton", 0));
MHHAbout->setText(QString());
} // retranslateUi
};
namespace Ui {
class Navigation_GuiClass: public Ui_Navigation_GuiClass {};
} // namespace Ui
QT_END_NAMESPACE
#endif
When I change the connect line in the constructor above to
connect(this->ui.pushButton, SIGNAL(clicked()), this, SLOT(on_pushButton_clicked()));
I get
QObject::connect: No such slot Navigation_Gui::this->on_pushButton_clicked() in navigation_gui.cpp:26
QObject::connect: (sender name: 'pushButton')
QObject::connect: (receiver name: 'Navigation_GuiClass')
Which is also odd.
I have made a user interface in Qt Designer and i now want to display the data.I want to make use of the multiple inheritance approach.Here is the code for the user interface.
/********************************************************************************
** Form generated from reading UI file 'prototypejI3444.ui'
**
** Created: Mon May 30 10:04:01 2011
** by: Qt User Interface Compiler version 4.7.0
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef PROTOTYPEJI3444_H
#define PROTOTYPEJI3444_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QGridLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QMainWindow>
#include <QtGui/QMenuBar>
#include <QtGui/QPushButton>
#include <QtGui/QStatusBar>
#include <QtGui/QTableView>
#include <QtGui/QVBoxLayout>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public:
QWidget *centralwidget;
QGridLayout *gridLayout;
QVBoxLayout *verticalLayout_2;
QLabel *label;
QVBoxLayout *verticalLayout_3;
QLineEdit *lineEdit;
QVBoxLayout *verticalLayout_4;
QLabel *label_2;
QVBoxLayout *verticalLayout_5;
QLineEdit *lineEdit_2;
QVBoxLayout *verticalLayout_6;
QLabel *label_3;
QVBoxLayout *verticalLayout_7;
QLineEdit *lineEdit_3;
QTableView *tableView;
QPushButton *pushButton_2;
QPushButton *pushButton_3;
QPushButton *pushButton_4;
QPushButton *pushButton_5;
QPushButton *pushButton_6;
QPushButton *pushButton;
QMenuBar *menubar;
QStatusBar *statusbar;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(800, 600);
centralwidget = new QWidget(MainWindow);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
gridLayout = new QGridLayout(centralwidget);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
verticalLayout_2 = new QVBoxLayout();
verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
label = new QLabel(centralwidget);
label->setObjectName(QString::fromUtf8("label"));
verticalLayout_2->addWidget(label);
gridLayout->addLayout(verticalLayout_2, 1, 0, 1, 1);
verticalLayout_3 = new QVBoxLayout();
verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3"));
lineEdit = new QLineEdit(centralwidget);
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
verticalLayout_3->addWidget(lineEdit);
gridLayout->addLayout(verticalLayout_3, 1, 1, 1, 1);
verticalLayout_4 = new QVBoxLayout();
verticalLayout_4->setObjectName(QString::fromUtf8("verticalLayout_4"));
label_2 = new QLabel(centralwidget);
label_2->setObjectName(QString::fromUtf8("label_2"));
verticalLayout_4->addWidget(label_2);
gridLayout->addLayout(verticalLayout_4, 2, 0, 1, 1);
verticalLayout_5 = new QVBoxLayout();
verticalLayout_5->setObjectName(QString::fromUtf8("verticalLayout_5"));
lineEdit_2 = new QLineEdit(centralwidget);
lineEdit_2->setObjectName(QString::fromUtf8("lineEdit_2"));
verticalLayout_5->addWidget(lineEdit_2);
gridLayout->addLayout(verticalLayout_5, 2, 1, 1, 1);
verticalLayout_6 = new QVBoxLayout();
verticalLayout_6->setObjectName(QString::fromUtf8("verticalLayout_6"));
label_3 = new QLabel(centralwidget);
label_3->setObjectName(QString::fromUtf8("label_3"));
verticalLayout_6->addWidget(label_3);
gridLayout->addLayout(verticalLayout_6, 3, 0, 1, 1);
verticalLayout_7 = new QVBoxLayout();
verticalLayout_7->setObjectName(QString::fromUtf8("verticalLayout_7"));
lineEdit_3 = new QLineEdit(centralwidget);
lineEdit_3->setObjectName(QString::fromUtf8("lineEdit_3"));
verticalLayout_7->addWidget(lineEdit_3);
gridLayout->addLayout(verticalLayout_7, 3, 1, 1, 1);
tableView = new QTableView(centralwidget);
tableView->setObjectName(QString::fromUtf8("tableView"));
gridLayout->addWidget(tableView, 0, 0, 1, 2);
pushButton_2 = new QPushButton(centralwidget);
pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
gridLayout->addWidget(pushButton_2, 2, 2, 1, 1);
pushButton_3 = new QPushButton(centralwidget);
pushButton_3->setObjectName(QString::fromUtf8("pushButton_3"));
gridLayout->addWidget(pushButton_3, 3, 2, 1, 1);
pushButton_4 = new QPushButton(centralwidget);
pushButton_4->setObjectName(QString::fromUtf8("pushButton_4"));
gridLayout->addWidget(pushButton_4, 1, 3, 1, 1);
pushButton_5 = new QPushButton(centralwidget);
pushButton_5->setObjectName(QString::fromUtf8("pushButton_5"));
gridLayout->addWidget(pushButton_5, 2, 3, 1, 1);
pushButton_6 = new QPushButton(centralwidget);
pushButton_6->setObjectName(QString::fromUtf8("pushButton_6"));
gridLayout->addWidget(pushButton_6, 3, 3, 1, 1);
pushButton = new QPushButton(centralwidget);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
gridLayout->addWidget(pushButton, 1, 2, 1, 1);
MainWindow->setCentralWidget(centralwidget);
tableView->raise();
pushButton_2->raise();
pushButton_3->raise();
pushButton_4->raise();
pushButton_5->raise();
pushButton_6->raise();
pushButton->raise();
menubar = new QMenuBar(MainWindow);
menubar->setObjectName(QString::fromUtf8("menubar"));
menubar->setGeometry(QRect(0, 0, 800, 18));
MainWindow->setMenuBar(menubar);
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));
label->setText(QApplication::translate("MainWindow", "FirstName:", 0, QApplication::UnicodeUTF8));
label_2->setText(QApplication::translate("MainWindow", "SecondName:", 0, QApplication::UnicodeUTF8));
label_3->setText(QApplication::translate("MainWindow", "City:", 0, QApplication::UnicodeUTF8));
pushButton_2->setText(QApplication::translate("MainWindow", "New", 0, QApplication::UnicodeUTF8));
pushButton_3->setText(QApplication::translate("MainWindow", "Delete", 0, QApplication::UnicodeUTF8));
pushButton_4->setText(QApplication::translate("MainWindow", "Next", 0, QApplication::UnicodeUTF8));
pushButton_5->setText(QApplication::translate("MainWindow", "Previous", 0, QApplication::UnicodeUTF8));
pushButton_6->setText(QApplication::translate("MainWindow", "First", 0, QApplication::UnicodeUTF8));
pushButton->setText(QApplication::translate("MainWindow", "Save", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // PROTOTYPEJI3444_H
In the multiple inheritance method there is a .h file and its corresponding .cpp.I want someone to guide me on where to make a connection to sqlite database(whether its in the .cpp file or the .h file) and how to communicate with the UI file i have shown to show data from the database on Qtableview.
Thanks.
You instantiate QSqlTableModel, associate it the the view using setModel, and initialize the appropriate table properties to the model. Do all of it in init.