QSQLITE "Driver not loaded" - qt

i have a problem with QSQLDATABASE. i'm using Qt 4.8.5
i get always Driver not loaded error .
i have check that QSQLITE driver is available
her is my code so far
article.h
#ifndef ARTICLE_H
#define ARTICLE_H
#include <QWidget>
#include <QtSql>
#include <QSqlDatabase>
namespace Ui {
class article;
}
class article : public QWidget
{
Q_OBJECT
public:
explicit article(QWidget *parent = 0);
~article();
void lastId(QString table);
bool changes();
void setChanges(bool change);
bool updates();
void setUpdates(bool update);
private slots:
void on_nouveaupushButton_clicked();
private:
Ui::article *ui;
bool m_detectChanges;
bool m_detectUpdates ;
};
#endif // ARTICLE_H
article.cpp
#include "article.h"
#include "ui_article.h"
#include <QMessageBox>
#include <databasemananger.h>
article::article(QWidget *parent) :
QWidget(parent),
ui(new Ui::article)
{
ui->setupUi(this);
m_detectChanges = false ;
m_detectUpdates = false;
// Setup
lastId("articles");
}
article::~article()
{
delete ui;
}
void article::lastId(QString table)
{
QSqlDatabase db = QSqlDatabase::database();
QSqlQuery query ;
QString queryString = "select seq from sqlite_sequence where name= ? ";
query.prepare(queryString);
query.addBindValue("articles");
if(!query.exec())
{
QMessageBox::critical(this,tr("Inventaire"),query.lastError().text());
return;
}
while(query.next())
{
ui->articleCodeLineEdit->setText("ART_" + QString::number(query.value(0).toInt() + 1));
return ;
}
if(ui->articleCodeLineEdit->text().isEmpty())
ui->articleCodeLineEdit->setText("ART_1");
}
bool article::changes()
{
return m_detectChanges ;
}
void article::setChanges(bool change)
{
m_detectChanges = change;
}
bool article::updates()
{
return m_detectUpdates;
}
void article::setUpdates(bool update)
{
m_detectUpdates = update ;
}
void article::on_nouveaupushButton_clicked()
{
// check changes
// get last id
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QSqlDatabase>
#include <article.h>
#include <QtSql>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_actionAjouter_nouveau_article_triggered();
private:
Ui::MainWindow *ui;
QSqlDatabase *m_db ;
article *m_fenetreArticle;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QtGlobal>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_fenetreArticle = new article(this);
m_fenetreArticle->setWindowFlags(Qt::Window);
m_db = new QSqlDatabase;
// Base de données traitement
m_db->setHostName("localhost");
m_db->setDatabaseName("E:/apprendreQt/gestionstock6/database/gestionStock4.db");
m_db->setPassword("");
m_db->setUserName("");
if(!m_db->open())
QMessageBox::critical(this,"erreur connecting",m_db->lastError().text());
}
MainWindow::~MainWindow()
{
m_db->close();
QSqlDatabase::removeDatabase("gestionstock4.db");
delete ui;
}
void MainWindow::on_actionAjouter_nouveau_article_triggered()
{
m_fenetreArticle->show();
}
main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

Don't use m_db = new QSqlDatabase;.
See the documentation :
QSqlDatabase::QSqlDatabase()
Creates an empty, invalid QSqlDatabase object. Use addDatabase(), removeDatabase(), and database() to get valid QSqlDatabase objects.
You specify which driver to use when you call the addDatabase() function :
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");

I figured out the probelm is cause by me
m_fenetreArticle needs the default database connexion , and i have creates
m_fenetreArticle object before creating the default connexion
mainwindow.cpp must be like so
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QtGlobal>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_db = new QSqlDatabase;
// Base de données traitement
m_db->setHostName("localhost");
m_db->setDatabaseName("E:/apprendreQt/gestionstock6/database/gestionStock4.db");
m_db->setPassword("");
m_db->setUserName("");
if(!m_db->open())
QMessageBox::critical(this,"erreur connecting",m_db->lastError().text());
m_fenetreArticle = new article(this);
m_fenetreArticle->setWindowFlags(Qt::Window);
}
MainWindow::~MainWindow()
{
m_db->close();
QSqlDatabase::removeDatabase("gestionstock4.db");
delete ui;
}
void MainWindow::on_actionAjouter_nouveau_article_triggered()
{
m_fenetreArticle->show();
}

Related

Couldn't render OpenGLES context in Qt

I am trying to use OpenGLES in a desktop platform. I have a class whose name is GraphicsViewer which is derived from QOpenGLWidget. When I set the QSurfaceFormat::renderableType to QSurfaceFormat::OpenGLES, I get the following errors and nothing is drawn on the widget. Can you help me to create an OpenGLES context in a desktop platform? My OS is Windows 10 and my Qt version is 5.12.3.
Errors:
QOpenGLWidget: Failed to create context
QOpenGLWidget: Failed to create context
qt.qpa.backingstore: composeAndFlush: QOpenGLContext creation failed
QOpenGLWidget: Failed to create context
qt.qpa.backingstore: composeAndFlush: makeCurrent() failed
qt.qpa.backingstore: composeAndFlush: makeCurrent() failed
Here is my codes...
main.cpp
#include "QtOpenGLES.h"
#include <QApplication>
#include <QSurfaceFormat>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QSurfaceFormat f;
f.setVersion(2, 0);
f.setRenderableType(QSurfaceFormat::OpenGLES);
QSurfaceFormat::setDefaultFormat(f);
QtOpenGLES w;
w.show();
return a.exec();
}
QtOpenGLES.h
#ifndef QTOPENGLES_H
#define QTOPENGLES_H
#include <QMainWindow>
namespace Ui {
class QtOpenGLES;
}
class QtOpenGLES : public QMainWindow
{
Q_OBJECT
public:
explicit QtOpenGLES(QWidget *parent = nullptr);
~QtOpenGLES();
private:
Ui::QtOpenGLES *ui;
};
#endif // QTOPENGLES_H
QtOpenGLES.cpp
#include "QtOpenGLES.h"
#include "ui_QtOpenGLES.h"
QtOpenGLES::QtOpenGLES(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::QtOpenGLES)
{
ui->setupUi(this);
}
QtOpenGLES::~QtOpenGLES()
{
delete ui;
}
GraphicsViewer.h
#ifndef GRAPHICSVIEWER_H
#define GRAPHICSVIEWER_H
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
class GraphicsViewer : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
public:
GraphicsViewer(QWidget* parent = nullptr);
// QOpenGLWidget interface
protected:
void initializeGL();
void paintGL();
};
GraphicsViewer.cpp
#include "GraphicsViewer.h"
#include <QtOpenGL>
GraphicsViewer::GraphicsViewer(QWidget *parent) :
QOpenGLWidget (parent)
{
}
void GraphicsViewer::initializeGL()
{
initializeOpenGLFunctions();
}
void GraphicsViewer::paintGL()
{
glClearColor(1, 0, 0, 1);
}

Signal is emitting, connection returns true, slot not triggering

This is the second way I have rearranged this, and it is doing the same thing, so now I seek help. There are no errors being thrown, the slot just never does anything.
There are two other connections that are working between the same two cpps, and I decided to add this third one that the main window triggers, to the main window.
on_line_edit_returnPressed(), is printing hol_num and that is where it ends. ReadyHollander emits and HolPub never does anything. What am I doing wrong?
mainwindow cpp
#include "wheelscannerui.h"
#include "./ui_wheelscannerui.h"
gui_image_node *m_gui_image_node;
WheelScannerUI::WheelScannerUI(QWidget *parent)
: QMainWindow(parent),
ui(new Ui::WheelScannerUI)
{
ui->setupUi(this);
connect(m_gui_image_node, &gui_image_node::ReadyImage, this, &WheelScannerUI::updateWheelImage);
connect(m_gui_image_node, &gui_image_node::OpenHollander, this, &WheelScannerUI::Open_No_ID);
connect(this, &WheelScannerUI::ReadyHollander, m_gui_image_node, &gui_image_node::HolPub);
qDebug() << connect(this, &WheelScannerUI::ReadyHollander, m_gui_image_node, &gui_image_node::HolPub);
ui->lineEdit->setVisible(false);
QMainWindow::showFullScreen();
}
WheelScannerUI::~WheelScannerUI()
{
delete ui;
}
void WheelScannerUI::Open_No_ID(QString qsteve)
{
ui->lineEdit->setVisible(true);
}
void WheelScannerUI::on_lineEdit_returnPressed()
{
QString hol_num = ui->lineEdit->text();
Q_EMIT ReadyHollander(hol_num);
ui->lineEdit->setVisible(false);
ui->lineEdit->clear();
qDebug() << hol_num;
}
main windows .h
#ifndef WHEELSCANNERUI_H
#define WHEELSCANNERUI_H
#include <QMainWindow>
#include <QtSql>
#include <QSqlQuery>
#include <QSqlDatabase>
#include <QSqlQueryModel>
#include "gui_image_node.h"
#include <QPixmap>
#include <ros/ros.h>
#include <std_msgs/String.h>
#include <std_msgs/Int64.h>
#include <sensor_msgs/image_encodings.h>
#include <nodelet/nodelet.h>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <opencv2/highgui/highgui.hpp>
#include <pluginlib/class_list_macros.h>
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <iostream>
extern gui_image_node *m_gui_image_node;
QT_BEGIN_NAMESPACE
namespace Ui { class WheelScannerUI; }
QT_END_NAMESPACE
class WheelScannerUI : public QMainWindow
{
Q_OBJECT
public:
WheelScannerUI(QWidget *parent = nullptr);
~WheelScannerUI();
WheelScannerUI *m_WheelScannerUI;
void connectionClose()
{
db.close();
db.removeDatabase(QSqlDatabase::defaultConnection);
}
bool connectionOpen()
{
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("~/wheels.db");
if(!db.open())
{
qDebug()<<("Database failed to open");
return false;
}
else{
qDebug()<<("database connected");
return true;
}
}
public slots:
Q_SLOT void Open_No_ID(QString qsteve);
Q_SLOT void open_db_table(); //trigger with a ros callback?
signals:
Q_SIGNAL void ReadyHollander(QString);
private slots:
void on_lineEdit_returnPressed();
void on_Mode_Button_clicked();
private:
Ui::WheelScannerUI *ui;
QSqlDatabase db;
};
#endif // WHEELSCANNERUI_H
node cpp
#include "gui_image_node.h"
gui_image_node::gui_image_node()
{
}
bool gui_image_node::init(int argc, char** argv)
{
m_pThread = new QThread();
this->moveToThread(m_pThread);
connect(m_pThread, &QThread::started, this, &gui_image_node::run);
ros::init(argc, argv, "wheels_gui_image");
if ( ! ros::master::check() )
{
return false;
}
ros::start();
ros::Time::init();
ros::NodeHandle nh;
hollander_pub = nh.advertise<std_msgs::String>("/hollander_chat", 1);
hol_trigger = nh.subscribe("awaiting_hollander", 1, &gui_image_node::Hollander_Screen_trigger_callback, this);
m_pThread->start();
return true;
}
void gui_image_node::Hollander_Screen_trigger_callback(const std_msgs::String::ConstPtr& msg)
{
std::string steve = msg->data;
QString qsteve = QString::fromStdString(steve);
Q_EMIT OpenHollander(qsteve);
}
void gui_image_node::HolPub(QString hol_num)
{
qDebug() << "received number";
std::string hol_num_conv = hol_num.toUtf8().constData();
std_msgs::String msg;
msg.data = hol_num_conv;
hollander_pub.publish(msg);
}
nodes .h
#ifndef GUI_IMAGE_NODE_H
#define GUI_IMAGE_NODE_H
#include <ros/ros.h>
#include <nodelet/nodelet.h>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <opencv2/highgui/highgui.hpp>
#include <std_msgs/String.h>
#include <QMainWindow>
#include <QObject>
#include <QSharedDataPointer>
#include <QWidget>
#include <QThread>
#include <string>
#include <QMutex>
#include <QDebug>
#include <QDialog>
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <iostream>
class gui_image_node : public QThread
{
Q_OBJECT
public:
gui_image_node();
~gui_image_node();
bool init(int argc, char** argv);
void Hollander_Screen_trigger_callback(const std_msgs::String::ConstPtr& msg);
protected:
public slots:
Q_SLOT void run();
Q_SLOT void HolPub(QString hol_num);
signals:
Q_SIGNAL void OpenHollander(QString);
private:
ros::Publisher hollander_pub;
ros::Subscriber hol_trigger;
QThread * m_pThread;
};
#endif // GUI_IMAGE_NODE_H
OK, I figured it out, connect(this, &WheelScannerUI::ReadyHollander, m_gui_image_node, &gui_image_node::HolPub, Qt::Directconnection);
Since this is being triggered from another thread, Directconnection allows the thread it is being emitted from to trigger the slot in a different thread.

How to use QTimer to view a image sequence?

In the program, I am trying to create a image player using QT. When I click a button in the UI, the program will create a image slideshow with a 2s pause. I tried to use the QTimer to such things, but failed to do so. Hence, I want to ask how to achieve my purpose by using QTimer.
Let me describe the flow of my program. When the user click a button in the main window, the sub-window showpic will be opened and then start showing each image for a pause of 2s in its qgraphsview. The images filepath are stored in the "QStringlist filenames".
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QFileSystemModel>
#include "showpic.h"
#include <QBasicTimer>
#include <QTimer>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void display(const QString & , ShowPic* );
private slots:
void tick();
void on_pushButton_clicked();
private:
Ui::MainWindow *ui;
QFileSystemModel *model;
QString filesPath;
ShowPic *showpic;
QStringList filenames;
QStringList::const_iterator m_imageIt;
QTimer m_timer;
};
#endif // MAINWINDOW_H
showpic.h
#ifndef SHOWPIC_H
#define SHOWPIC_H
#include <QWidget>
namespace Ui {
class ShowPic;
}
class ShowPic : public QWidget
{
Q_OBJECT
public:
explicit ShowPic(QWidget *parent = 0);
~ShowPic();
private:
Ui::ShowPic *ui;
public:
void addPixmap(const QPixmap &pixmap);
};
#endif // SHOWPIC_H
main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QFileDialog>
#include<QFileSystemModel>
#include<QStringList>
#include <QTreeView>
#include <QGraphicsScene>
#include <QTime>
#include <QThread>
#include <QDebug>
#include <iostream>
#include <QTimer>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
filenames.append("C:\\test\\image.jpg");
filenames.append("C:\\test\\apple.jpg");
filenames.append("C:\\test\\orange.jpg");
filenames.append("C:\\test\\lemon.jpg");
filenames.append("C:\\test\\grape.jpg");
m_imageIt = filenames.begin();
m_timer.setInterval(5000);
connect(&m_timer, SIGNAL(timeout()), this, SLOT(tick()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::display(const QString & filename, ShowPic* showpic) {
showpic->addPixmap(filename);
}
void MainWindow::tick(){
showpic = new ShowPic();
showpic->show();
display(*m_imageIt, showpic);
m_imageIt ++;
}
/*
void timerEvent(QTimerEvent * ev) {
if (ev->timerId() == m_timer.timerId()) tick();
}*/
void MainWindow::on_pushButton_clicked()
{
/*showpic = new ShowPic();
QPixmap pixmap("C:\\test\\image.jpg");
showpic->addPixmap(pixmap);
showpic->show();*/
m_timer.start();
}
showpic.cpp
#include "showpic.h"
#include "ui_showpic.h"
#include <QThread>
ShowPic::ShowPic(QWidget *parent) :
QWidget(parent),
ui(new Ui::ShowPic)
{
ui->setupUi(this);
ui->graphicsView->setScene(new QGraphicsScene);
}
ShowPic::~ShowPic()
{
delete ui;
}
void ShowPic::addPixmap(const QPixmap &pixmap){
ui->graphicsView->scene()->addPixmap(pixmap);
}
The compiling message error:
The error has nothing to do with the timer, it is because you forgot to declare display(), tick(), and timerEvent() as part of the MainWindow:: class, so they cannot access MainWindow members.
The timer should be even easier to use than your code. First I recommend you use a QTimer instead of QBasicTimer. Then you can simply connect to its timeout() signal.
mainwindow.h
#include <QTimer>
QTimer m_timer;
mainwindow.cpp
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
...
m_imageIt = filenames.begin();
m_timer.setInterval(5000);
connect(&m_timer, SIGNAL(timeout()), this, SLOT(tick()));
}
void MainWindow::on_pushButton_clicked()
{
m_timer.start();
}
You do not need timerEvent() function at all.

Need help connecting signal from thread to slot in GUI

mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void disableStartButton();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
myobject.h
#ifndef MYOBJECT_H
#define MYOBJECT_H
#include <QtCore>
class MyObject : public QObject
{
Q_OBJECT
public:
explicit MyObject(QObject *parent = 0);
void doSetup(QThread &cThread);
signals:
void disableStartButton();
public slots:
void doWork();
};
#endif // MYOBJECT_H
main.cpp:
#include "mainwindow.h"
#include "myobject.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
QThread cThread;
MyObject cObject;
cObject.doSetup(cThread);
cObject.moveToThread(&cThread);
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);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::disableStartButton() {
ui->pushButton->setEnabled(false);
}
myobject.h:
#include "myobject.h"
#include <QDebug>
MyObject::MyObject(QObject *parent) :
QObject(parent)
{
}
void MyObject::doSetup(QThread &cThread)
{
connect(&cThread, SIGNAL(started()), this, SLOT(doWork()));
connect(ui->pushButton, SIGNAL(clicked()), &cThread, SLOT(start())); // (1)
connect(this, SIGNAL(disableStartButton()), ui, SLOT(disableStartButton())); // (2)
}
void MyObject::doWork()
{
emit disableStartButton();
qDebug() << "1";
}
I'm trying to do two things.
(1): As soon pushButton is clicked, I want cThread to start.
(2): As soon as cThread starts, it does: emit disableStartButton();. I want to connect disableStartButton() to disableStartButton() in mainwindow.cpp.
For (1), I get this error:
myobject.cpp:12: error: C2065: 'ui' : undeclared identifier
Of course, there ui is undefined. You try to connect ui->pushButton
connect(ui->pushButton, SIGNAL(clicked()), &cThread, SLOT(start())); // (1)
in file myobject.cpp, when your ui declared only in mainwindow.cpp
You have to connect pushbutton to your thread within mainwindow.cpp file, hope that helps
By the way, you should create your objects NOT in main.cpp but, in your case, in mainwindow.cpp, move lines
QThread cThread;
MyObject cObject;
cObject.doSetup(cThread);
cObject.moveToThread(&cThread);
to file mainwindow.cpp in constructor, for example
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
right after ui->setupUi(this);

Parent and Child Window Communication in Qt - Child Window opens twice

I have two windows, one parent and one child. In parent window, I have a Next button, which onClick()'ed, opens up child window, but in my case two child windows are opening, what is the mistake am doing!?
Here are my codes:
.h files
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <info.h>
#include <QtGui>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
protected:
void changeEvent(QEvent *e);
private:
Ui::MainWindow *ui;
void setSignals();
private slots:
void process();
};
#endif // MAINWINDOW_H
info.h
#ifndef INFO_H
#define INFO_H
#include <QMainWindow>
namespace Ui {
class info;
}
class info : public QMainWindow {
Q_OBJECT
public:
info(QWidget *parent = 0);
~info();
protected:
void changeEvent(QEvent *e);
private:
Ui::info *ui;
};
#endif // INFO_H
.cpp files
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtGui/QApplication>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
setSignals();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::setSignals(){
connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(process()));
connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(close()));
}
void MainWindow::process(){
info *i;
i = new info;
this -> hide();
i -> show();
}
info.cpp
#include "info.h"
#include "ui_info.h"
info::info(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::info)
{
ui->setupUi(this);
}
info::~info()
{
delete ui;
}
void info::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
I solved it, here was the problem:
In designer header file i.e., in ui_mainwindow.h, I have:
QObject::connect(pushButton, SIGNAL(clicked()), MainWindow, SLOT(process()));
QObject::connect(pushButton_2, SIGNAL(clicked()), MainWindow, SLOT(close()));
and in the source file i.e., mainwindow.cpp in setSignals(), I have again stated:
void MainWindow::setSignals()
{
connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(process()));
connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(close()));
}
So with the two connects, we get two calls to process() , we have to comment anyone to show only one child window. That's it :-)

Resources