URGENT : How to Show Another Window From MainWindow in QT using c++
-
@Jasmin-Quinn you are not following as suggested..
Decide where do you want to have the instance of game.
Follow only the steps 1)2)3) suggested earlier and make sure main is not having any game object pointer and
MainWindow.h also should not have any game*. -
@Jasmin-Quinn move the declaration of
Game *game to MainWindow.h as global declaration -
This post is deleted!
-
@Jasmin-Quinn I hope Game *game declared in MainWindow.h only..
-
@Jasmin-Quinn paste MainWindow.h code here
Hope it's having below statements in the beginning
#ifdef MAINWINDOW_H
#define MAINWINDOW_H -
@nagesh ```
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "joueur.h"
#include "partie.h"
#include "game.h"
#include "qcustomplot.h"
#include "notepad.h"
#include "camera.h"
#include "qrplusplus.h"
#include <QPropertyAnimation>#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACEGame *game;
class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
MainWindow(QWidget *parent = nullptr);
~MainWindow();private slots:
void on_ajouter_joueur_clicked();void on_supprimer_joueur_clicked(); void on_tab_afficher_joueur_activated(const QModelIndex &index); void on_modifier_joueur_clicked(); void on_ajouter_partie_clicked(); void on_tab_afficher_partie_activated(const QModelIndex &index); void on_supprimer_partie_clicked(); void on_modifier_partie_clicked(); void on_chercher_joueur_clicked(); void on_chercher_partie_clicked(); void on_trier_joueur_clicked(); void on_trier_partie_clicked(); void on_imprimer_partie_clicked(); void on_excel_joueur_clicked(); void showTime(); void on_envoyer_mail_released(); void on_afficher_tout_joueurs_clicked(); void on_afficher_tout_parties_clicked(); void on_stat_joueur_clicked(); void on_notes_clicked(); void on_ajouter_photo_j_clicked(); void on_prendre_photo_clicked(); void on_qrcode_clicked(); void on_lancer_partie_clicked();
private:
Ui::MainWindow *ui;
Joueur J;
Partie P;Notepad *notepad; Camera *camera; QRplusplus *qrcode; QPropertyAnimation * animation; QCustomPlot *customPlot; QString fileNameImage ; QPixmap photo ; QByteArray image; QPixmap pixmap; QByteArray array;
};
#endif // MAINWINDOW_H -
@Jasmin-Quinn okay fine, I repeat that my first post is the solution to this application integration.
I repost the working solution. (I tried integrating github project which is working fine )
Solution as per the existing implementation of chessboard application (Just to make the integration works fine)
1)Copy the required files(chess project files) to the existing project.2)In Mainwindow.cpp create the global game object pointer;
Game *game=nullptr;
//make sure Game *game; exists only in the Mainwindow.cpp
//Earlier crash was because there were two instance game * one in Manwindow.h as member variable and other with main.cpp.3)In Mainwindow.cpp include the game.h file
#include "game.h"4)In on_lancer_partie_clicked() create the instance of it
game = new Game();
game->show();
game->displayMainMenu();Note: Assumption that github code remains unaltered.
-
So basically back to square one.
I still believe that SUB_DIRS would make life easier.
( adding game code from github was a snap - but it works as independent project only.The qmake / management part of SUB_DIRS is OK, however, it definitely requires better knowledge of "make" ( am I repeating myself here?).
There are many options in qmake and it will just take some time to figure out how to
have (main) project
and be able to select real sub-project.I have done that on "C level " - using MDI / QProcess and I'll try to get same result
using qmake. -
@nagesh said in URGENT : How to Show Another Window From MainWindow in QT using c++:
@Jasmin-Quinn okay fine, I repeat that my first post is the solution to this application integration.
I repost the working solution. (I tried integrating github project which is working fine )
Solution as per the existing implementation of chessboard application (Just to make the integration works fine)
1)Copy the required files(chess project files) to the existing project.2)In Mainwindow.cpp create the global game object pointer;
Game *game=nullptr;
//make sure Game *game; exists only in the Mainwindow.cpp
//Earlier crash was because there were two instance game * one in Manwindow.h as member variable and other with main.cpp.3)In Mainwindow.cpp include the game.h file
#include "game.h"4)In on_lancer_partie_clicked() create the instance of it
game = new Game();
game->show();
game->displayMainMenu();Note: Assumption that github code remains unaltered.
If I borrow Qt "cALLBACK" terminology you probably want
main window event loop
game project event loopor in human -
run game project event loop INSIDE main project event loop
or in "pseudocode " (no buttons pushing )int main(int argc, char *argv[])
{
QApplication main ptoject (argc, argv); main project event loop
QApplication game project (argc, argv); game project event loop
game = new Game();
game->show();
game->displayMainMenu();
return game project .exec();
return main project .exec();
} -
Is it correct to say that now the "main project" has all the code of "chess" added so basically there is only one application running?
The objective to "have two windows" has been met, however, adding more "child applications" using same philosophy of "cut and paste" is not what " reusing code " means to me.