Added QMenuBar in QDialog it showing but sub menus dosn't open - c++

i added QMenuBar in QDialog using layout that is set in Designer and then manully adding the QMenuBar , when running the application and the QDialog runs i see the QMenuBar with only the menu header without the opening sub menu :
here is my code :
this is the header file generated from the Designer :
QT_BEGIN_NAMESPACE
class Ui_AutoDialog
{
public:
QVBoxLayout *verticalLayout;
QWidget *widget_menuBarHolder;
QVBoxLayout *verticalLayout_2;
QVBoxLayout *verticalLayout_menuBarLayOut;
QWebView *webView;
QWidget *widget;
void setupUi(QDialog *AutoDialog)
{
if (AutoDialog->objectName().isEmpty())
AutoDialog->setObjectName(QString::fromUtf8("AutoDialog"));
AutoDialog->resize(436, 365);
verticalLayout = new QVBoxLayout(AutoDialog);
verticalLayout->setSpacing(0);
verticalLayout->setContentsMargins(0, 0, 0, 0);
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
widget_menuBarHolder = new QWidget(AutoDialog);
widget_menuBarHolder->setObjectName(QString::fromUtf8("widget_menuBarHolder"));
widget_menuBarHolder->setMinimumSize(QSize(0, 20));
verticalLayout_2 = new QVBoxLayout(widget_menuBarHolder);
verticalLayout_2->setSpacing(0);
verticalLayout_2->setContentsMargins(0, 0, 0, 0);
verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
verticalLayout_menuBarLayOut = new QVBoxLayout();
verticalLayout_menuBarLayOut->setSpacing(0);
verticalLayout_menuBarLayOut->setObjectName(QString::fromUtf8("verticalLayout_menuBarLayOut"));
verticalLayout_2->addLayout(verticalLayout_menuBarLayOut);
verticalLayout->addWidget(widget_menuBarHolder);
webView = new QWebView(AutoDialog);
webView->setObjectName(QString::fromUtf8("webView"));
webView->setUrl(QUrl("about:blank"));
verticalLayout->addWidget(webView);
widget = new QWidget(AutoDialog);
widget->setObjectName(QString::fromUtf8("widget"));
widget->setMinimumSize(QSize(0, 20));
verticalLayout->addWidget(widget);
retranslateUi(AutoDialog);
QMetaObject::connectSlotsByName(AutoDialog);
} // setupUi
void retranslateUi(QDialog *AutoDialog)
{
AutoDialog->setWindowTitle(QApplication::translate("AutoDialog", "Dialog", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class AutoDialog: public Ui_AutoDialog {};
} // namespace Ui
QT_END_NAMESPACE
and here is the QDialog constructor , the part where is building the QMenuBAr:
ui.setupUi(this);
/*ui.verticalLayout_menuBarLayOut->addWidget(SetMenuBar());
ui.verticalLayout_menuBarLayOut->setMargin(0);
ui.verticalLayout_menuBarLayOut->setSpacing(0);*/
m_actionClose = new QAction(this);
m_actionClose->setObjectName(QString::fromUtf8("actionClose"));
m_actionPreferences = new QAction(this);
m_actionPreferences->setObjectName(QString::fromUtf8("actionPreferences"));
m_menubar = new QMenuBar(this);
m_menubar->setObjectName(QString::fromUtf8("menubar"));
m_menubar->setGeometry(QRect(0, 0, 314, 18));
m_menuFile = new QMenu(m_menubar);
m_menuFile->setObjectName(QString::fromUtf8("menuFile"));
m_menuSettings = new QMenu(m_menubar);
m_menuSettings->setObjectName(QString::fromUtf8("menuSettings"));
m_menubar->setMinimumSize(QSize(0, 20));
ui.verticalLayout_menuBarLayOut->setMenuBar(m_menubar);
m_menubar->addAction(m_menuFile->menuAction());
m_menubar->addAction(m_menuSettings->menuAction());
m_menuFile->addSeparator();
m_menuFile->addAction(m_actionClose);
m_menuSettings->addAction(m_actionPreferences);
m_actionClose->setText(QApplication::translate("MainWindow", "Close", 0, QApplication::UnicodeUTF8));
m_actionPreferences->setText(QApplication::translate("MainWindow", "Preferences", 0, QApplication::UnicodeUTF8));
m_menuFile->setTitle(QApplication::translate("MainWindow", "File", 0, QApplication::UnicodeUTF8));
m_menuSettings->setTitle(QApplication::translate("MainWindow", "Settings", 0, QApplication::UnicodeUTF8));
bar = new QStatusBar(this);
bar->setMinimumSize(QSize(0, 20));
ui.verticalLayout->removeWidget(ui.widget);
ui.verticalLayout->addWidget(bar);
ui.verticalLayout->setMargin(0);
ui.verticalLayout->setSpacing(0);
pb = new QProgressBar(bar);
pb->setTextVisible(false);
pb->hide();
bar->addPermanentWidget(pb);
what is wrong here why i can't see the sub menus.. Close & Preferences?

I'm not familiar with the way you're adding the menus, because I usually add menus to a menubar in a different way.
Try
m_menubar->addMenu( m_menuFile );
m_menubar->addMenu( m_menuSettings );
instead of
m_menubar->addAction(m_menuFile->menuAction());
m_menubar->addAction(m_menuSettings->menuAction());
and let me know if that worked. If not, there must be another problem I will look into.

Related

Keep widget central forever after inserting an spaceritem

I want to customize a titlebar:
class TitlebarWidget : public QWidget {
Q_OBJECT
public:
TitlebarWidget(QWidget* parent = nullptr): QWidget(parent) {
setupUi();
}
virtual ~TitlebarWidget();
private:
void setupUi(){
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
// layout->addSpacerItem(new QSpacerItem(width(), height(),
QSizePolicy::Fixed, QSizePolicy::Fixed));
m_homeButton = new QPushButton(this);
m_homeButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
m_homeButton->setMinimumWidth(50);
m_homeButton->setMaximumWidth(50);
m_homeButton->setText(tr("Home"));
layout->addWidget(m_homeButton);
QLabel* label = new QLabel(this);
label->setText("Titlebar");
layout->addWidget(label, 0, Qt::AlignCenter);
m_synButton = new QPushButton(this);
m_synButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
m_synButton->setMinimumWidth(100);
m_synButton->setMaximumWidth(100);
m_homeButton->setText(tr("Sync"));
}
QPushButton* m_synButton;
QPushButton* m_homeButton;
QPushButton* m_settingButton;
QRCodeWidget* m_synPhoneWidget;
};
The titlebar is as follows:
Home button is covered by the three circles at top-left corner, so I insert an spacer-item at the beginning:
layout->addSpacerItem(new QSpacerItem(width(), height(), QSizePolicy::Fixed, QSizePolicy::Fixed));
And the titlebar is like:
I found the text 'Titlebar' was obviously deviated from the center, but I want keep it central. who can help me with a workaround or a better alternative?
Use layout->addSpacing() instead and addStretch works for me.

QT dynamically generate label, LineEdit, Button

I want to do serial communication in the QT inside, according to the number of serial ports to dynamically generate label, LineEdit, Button, and these three buttons can pull down the scroll bar when the size of the interface, how to do well, I write this below is dead of.
The effect of encapsulation into a method
The interface was washed last
Define QGridLayout insude QScrollArea. And add your new widgets into
that layout in code. QGridLayout::addWidget
Define table where you will show several widgets in table cells. That real complicated way.
void BaseUi::BaseScrollArea()
{
QScrollArea *pArea = new QScrollArea();
QWidget *pWidget = new QWidget();
pWidget->setStyleSheet("QWidget" "{background:white;}");
m_vbox_layout = new QVBoxLayout();
m_vbox_layout->addSpacerItem(new QSpacerItem(100, 30,
QSizePolicy::Expanding, QSizePolicy::Expanding));
pWidget->setLayout(m_vbox_layout);
pArea->setWidget(pWidget);
pArea->setWidgetResizable(true);
m_main_layout = new QVBoxLayout();
m_main_layout->addWidget(pArea);
}
void BaseUi::addAutoRecordUi(QString lab_neme, QString ledit_name)
{
QWidget *page = new QWidget;
QGridLayout *layout = new QGridLayout(page);
QLabel *label = new QLabel;
label->setText(lab_neme);
label->setFont(font());
QLineEdit *ledit = new QLineEdit;
ledit->setText(ledit_name);
ledit->setFont(font());
layout->addWidget(label, 0, 1);
layout->addWidget(ledit, 0, 2);
page->setLayout(layout);
m_vbox_layout->insertWidget(m_vbox_layout->count()-1, page);
}
void BaseUi::addMulRecordUi(QString lab_neme, QString ledit_name, QString
but_name)
{
QWidget *page = new QWidget;
QGridLayout *layout = new QGridLayout(page);
QLabel *label = new QLabel;
label->setText(lab_neme);
label->setFont(font());
QLineEdit *ledit = new QLineEdit;
ledit->setText(ledit_name);
ledit->setFont(font());
QPushButton *but = new QPushButton(but_name);
but->setFont(font());
layout->addWidget(label, 0, 1);
layout->addWidget(ledit, 0, 2);
layout->addWidget(but, 0, 3);
page->setLayout(layout);
m_vbox_layout->insertWidget(m_vbox_layout->count()-1, page);
}

QResizeEvent causes SIGSEGV

My purpose is to use a class called overlay.h to add a rectangular box and text on top of a Widget (MarbleWidget). Here below is my code for the GUI. I tried to remove all unnecessary parts:
mainwindow.cpp
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
setupUi(this);
}
MainWindow::~MainWindow()
{
}
void MainWindow::resizeEvent(QResizeEvent *event)
{
overlay->resize(event->size()); //////////////// CAUSES SIGSEGV!!!!!!!!!!!!!
event->accept();
}
void MainWindow::setupUi(QMainWindow *MainWindow)
{
MainWindow->showMaximized();
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(MainWindow->sizePolicy().hasHeightForWidth());
MainWindow->setSizePolicy(sizePolicy);
MainWindow->setTabShape(QTabWidget::Rounded);
QWidget *centralwidget = new QWidget(MainWindow);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
sizePolicy.setHeightForWidth(centralwidget->sizePolicy().hasHeightForWidth());
centralwidget->setSizePolicy(sizePolicy);
centralwidget->setLayoutDirection(Qt::LeftToRight);
QGridLayout *gridLayout_4 = new QGridLayout(centralwidget);
gridLayout_4->setObjectName(QString::fromUtf8("gridLayout_4"));
QSplitter *splitter_4 = new QSplitter(centralwidget);
splitter_4->setObjectName(QString::fromUtf8("splitter_4"));
splitter_4->setOrientation(Qt::Horizontal);
QTabWidget *tabWidget_2 = new QTabWidget(splitter_4);
tabWidget_2->setObjectName(QString::fromUtf8("tabWidget_2"));
sizePolicy.setHeightForWidth(tabWidget_2->sizePolicy().hasHeightForWidth());
tabWidget_2->setSizePolicy(sizePolicy);
tabWidget_2->setMaximumSize(QSize(443, 16777));
tabWidget_2->setAutoFillBackground(true);
tabWidget_2->setTabPosition(QTabWidget::West);
tabWidget_2->setTabShape(QTabWidget::Rounded);
tabWidget_2->setIconSize(QSize(30, 16));
QWidget *tab_10 = new QWidget();
tab_10->setObjectName(QString::fromUtf8("tab_10"));
QGridLayout *gridLayout = new QGridLayout(tab_10);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
QVBoxLayout *verticalLayout_4 = new QVBoxLayout();
verticalLayout_4->setObjectName(QString::fromUtf8("verticalLayout_4"));
QHBoxLayout *horizontalLayout_7 = new QHBoxLayout();
horizontalLayout_7->setObjectName(QString::fromUtf8("horizontalLayout_7"));
QLabel *label_3 = new QLabel(tab_10);
label_3->setObjectName(QString::fromUtf8("label_3"));
horizontalLayout_7->addWidget(label_3);
verticalLayout_4->addLayout(horizontalLayout_7);
QTreeView *treeView_4 = new QTreeView(tab_10);
treeView_4->setObjectName(QString::fromUtf8("treeView_4"));
QStandardItemModel *standardModel = new QStandardItemModel ;
QStandardItem *rootNode = standardModel->invisibleRootItem();
treeView_4->setModel(standardModel);
verticalLayout_4->addWidget(treeView_4);
gridLayout->addLayout(verticalLayout_4, 0, 0, 1, 1);
tabWidget_2->addTab(tab_10, QString());
treeView_4->raise();
Marble::MarbleWidget* MarbleWidget = new Marble::MarbleWidget(splitter_4);
splitter_4->addWidget(MarbleWidget);
splitter_4->setStretchFactor(0,0);
splitter_4->setStretchFactor(1,6);
gridLayout_4->addWidget(splitter_4, 0, 0, 1, 1);
MainWindow->setCentralWidget(centralwidget);
MarbleWidget->raise();
tabWidget_2->raise();
overlay = new Overlay(MarbleWidget);
overlay->raise();
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
overlay.h
#include <QWidget>
#include <QPainter>
class Overlay : public QWidget
{
public:
Overlay(QWidget *parent);
protected:
void paintEvent(QPaintEvent *event);
};
overlay.cpp
#include "overlay.h"
Overlay::Overlay(QWidget *parent)
: QWidget(parent)
{
setPalette(Qt::transparent);
setAttribute(Qt::WA_TransparentForMouseEvents);
}
void Overlay::paintEvent(QPaintEvent *event)
{
QFont font;
font.setStyleHint(QFont::Helvetica, QFont::PreferAntialias);
font.setPointSize(10);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(QColor(10, 10, 10, 255));
painter.fillRect(QRect(50, 50, 100, 100), QColor(100, 100, 100, 120));
painter.setFont(font);
painter.drawText(20, 20, "hi..............................");
}
The problem is that overlay->resize(event->size()); causes SIGSEGV when the core runs that line.
What is wrong with the code, how can I fix it?
The problem is solved by Thiago from freenode.
He pointed that MainWindow->showMaximized(); causes resize() event to be occurred before overlay is initialized. Removing that line or moving it to after the initialization solves the problem.
Take a look at official documentation: QWidget, Qt5 at resize method. Here you can read
Warning: Calling resize() or setGeometry() inside resizeEvent() can lead to infinite recursion.
You are doing exactly the same. To avoid infinite recursion and respectively your SIGSEGV you can (descending order of difficulty, descending order of true-way):
overwrite your resizeEvent() in Overlay and comment that line in MainWindow's resizeEvent;
in MainWindow's resizeEvent emit signal like mainWindowSizeChanged(QSize) and connect it to your Overlay's slot;
do QTimer::singleShot(...) in MainWindow's resizeEvent, so it will call a given slot after a given time interval.

Qt 4: How to insert QAction in menu of mainwindow

My problem is to get the QAction of custom widget from the outside and insert in menu of mainwindow. There is QActionWidget but it inserts custom widget in menu.
class QDESIGNER_WIDGET_EXPORT Photo_list: public QWidget
{
Q_OBJECT
public:
Photo_list(QWidget* parent = 0);
~Photo_list();
int count();
QString returnImagePath(const int i);
void sendSignalImageLoaded();
public slots:
void addImagePath();
void deleteImagePath();
signals:
void imageLoaded(int count);
//private:
public:
Ui::Photo_list *m_photo_list_ui;
QStringList m_image_path_list;
};
class Ui_Photo_list
{
public:
QAction *addImageAction;
QAction *deleteImageAction;
QGridLayout *gridLayout;
QListWidget *listWidget;
void setupUi(QWidget *Photo_list)
{
if (Photo_list->objectName().isEmpty())
Photo_list->setObjectName(QString::fromUtf8("Photo_list"));
Photo_list->resize(274, 210);
addImageAction = new QAction(Photo_list);
addImageAction->setObjectName(QString::fromUtf8("addImageAction"));
deleteImageAction = new QAction(Photo_list);
deleteImageAction->setObjectName(QString::fromUtf8("deleteImageAction"));
gridLayout = new QGridLayout(Photo_list);
gridLayout->setContentsMargins(0, 0, 0, 0);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
gridLayout->setHorizontalSpacing(0);
listWidget = new QListWidget(Photo_list);
listWidget->setObjectName(QString::fromUtf8("listWidget"));
listWidget->setTextElideMode(Qt::ElideMiddle);
listWidget->setMovement(QListView::Static);
listWidget->setResizeMode(QListView::Adjust);
listWidget->setViewMode(QListView::IconMode);
gridLayout->addWidget(listWidget, 0, 0, 1, 1);
retranslateUi(Photo_list);
QMetaObject::connectSlotsByName(Photo_list);
} ...
How to add QAction *addImageAction in ( * )? (see comment below)
class Ui_Cpdfa
{
public:
QAction *createPdfAction;
QWidget *centralwidget;
QGridLayout *gridLayout_2;
QGridLayout *gridLayout;
QLineEdit *pdfPathLineEdit;
QPushButton *findPdfPathButton;
Photo_list *photo_list;
QToolBar *toolBar;
QMenuBar *menuBar;
QMenu *menu;
QMenu *menu_2;
void setupUi(QMainWindow *Cpdfa)
{
if (Cpdfa->objectName().isEmpty())
Cpdfa->setObjectName(QString::fromUtf8("Cpdfa"));
Cpdfa->resize(386, 303);
createPdfAction = new QAction(Cpdfa);
createPdfAction->setObjectName(QString::fromUtf8("createPdfAction"));
centralwidget = new QWidget(Cpdfa);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
gridLayout_2 = new QGridLayout(centralwidget);
gridLayout_2->setObjectName(QString::fromUtf8("gridLayout_2"));
gridLayout = new QGridLayout();
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
pdfPathLineEdit = new QLineEdit(centralwidget);
pdfPathLineEdit->setObjectName(QString::fromUtf8("pdfPathLineEdit"));
gridLayout->addWidget(pdfPathLineEdit, 0, 0, 1, 1);
findPdfPathButton = new QPushButton(centralwidget);
findPdfPathButton->setObjectName(QString::fromUtf8("findPdfPathButton"));
gridLayout->addWidget(findPdfPathButton, 0, 1, 1, 1);
photo_list = new Photo_list(centralwidget);
photo_list->setObjectName(QString::fromUtf8("photo_list"));
gridLayout->addWidget(photo_list, 1, 0, 1, 2);
gridLayout_2->addLayout(gridLayout, 0, 0, 1, 1);
Cpdfa->setCentralWidget(centralwidget);
toolBar = new QToolBar(Cpdfa);
toolBar->setObjectName(QString::fromUtf8("toolBar"));
Cpdfa->addToolBar(Qt::TopToolBarArea, toolBar);
menuBar = new QMenuBar(Cpdfa);
menuBar->setObjectName(QString::fromUtf8("menuBar"));
menuBar->setGeometry(QRect(0, 0, 386, 21));
menu = new QMenu(menuBar);
menu->setObjectName(QString::fromUtf8("menu"));
menu_2 = new QMenu(menuBar);
menu_2->setObjectName(QString::fromUtf8("menu_2"));
Cpdfa->setMenuBar(menuBar);
toolBar->addAction(createPdfAction); //!!(*)
toolBar->addSeparator();
menuBar->addAction(menu->menuAction());
menuBar->addAction(menu_2->menuAction());
menu->addSeparator();
menu_2->addAction(createPdfAction); //!!(*)
retranslateUi(Cpdfa);
QMetaObject::connectSlotsByName(Cpdfa);
} // setupUi
I guess you are using Qt creator and designing forms separately with the form editor.
Your problem is acutally that you want the class A(a "larger" widget which comprises the subobjects) to access members in the namespace of its subobject B(your photo_list widget).
To do this,
Move the inclusion "ui_B.h" from B.cpp to B.h
Inside B.h make the private memeber Ui::B *ui; public (or you can have A and B become friends)
After including "B.h" and having a subobject pointer *B, you can call B->ui->actionXXX in A to access all memebers of B, since B->ui points to the namespace that includes all memebers created from B.ui file (which turn out to be inside "ui_B.h")

Qt QTableView Multiple Inheritance Method

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.