Fixed issue with semgentation fault occuring when application closes and when reopening keyManagement window

This commit is contained in:
amazing-username
2017-07-22 14:27:32 -05:00
parent 33c23cfc10
commit de5b56e84f
4 changed files with 19 additions and 24 deletions
+7 -1
View File
@@ -3,7 +3,6 @@
#include<QWidget> #include<QWidget>
#include<string> #include<string>
#include<sstream> #include<sstream>
#include<iostream>
#include<cstdlib> #include<cstdlib>
#include<fstream> #include<fstream>
#include<ios> #include<ios>
@@ -17,6 +16,7 @@ KeyManagementWindow::KeyManagementWindow(QWidget* parent) : QDialog(parent)
comboBoxOfKeys = unique_ptr<QComboBox>{new QComboBox{}}; comboBoxOfKeys = unique_ptr<QComboBox>{new QComboBox{}};
valueOfKey = unique_ptr<QLineEdit>{new QLineEdit{}}; valueOfKey = unique_ptr<QLineEdit>{new QLineEdit{}};
generateNewDefaultKeys = unique_ptr<QPushButton>{new QPushButton(tr("Generate New Default Key"))}; generateNewDefaultKeys = unique_ptr<QPushButton>{new QPushButton(tr("Generate New Default Key"))};
closeButton = unique_ptr<QPushButton>{new QPushButton(tr("close"))};
vBox = unique_ptr<QVBoxLayout>{new QVBoxLayout}; vBox = unique_ptr<QVBoxLayout>{new QVBoxLayout};
hBox = unique_ptr<QHBoxLayout>{new QHBoxLayout}; hBox = unique_ptr<QHBoxLayout>{new QHBoxLayout};
@@ -27,6 +27,7 @@ KeyManagementWindow::KeyManagementWindow(QWidget* parent) : QDialog(parent)
hBox.get()->addWidget(valueOfKey.get()); hBox.get()->addWidget(valueOfKey.get());
hBox2.get()->addWidget(generateNewDefaultKeys.get()); hBox2.get()->addWidget(generateNewDefaultKeys.get());
hBox2.get()->addWidget(closeButton.get());
vBox.get()->addLayout(hBox.get()); vBox.get()->addLayout(hBox.get());
vBox.get()->addLayout(hBox2.get()); vBox.get()->addLayout(hBox2.get());
@@ -40,6 +41,7 @@ KeyManagementWindow::KeyManagementWindow(QWidget* parent) : QDialog(parent)
QObject::connect(comboBoxOfKeys.get(), SIGNAL(currentIndexChanged(int)), SLOT(test())); QObject::connect(comboBoxOfKeys.get(), SIGNAL(currentIndexChanged(int)), SLOT(test()));
QObject::connect(generateNewDefaultKeys.get(), SIGNAL(clicked()), this, SLOT(generation())); QObject::connect(generateNewDefaultKeys.get(), SIGNAL(clicked()), this, SLOT(generation()));
QObject::connect(closeButton.get(), SIGNAL(clicked()), this, SLOT(exitApplication()));
} }
@@ -78,3 +80,7 @@ void KeyManagementWindow::generation()
gk.keyMove(); gk.keyMove();
gk.keyDump(); gk.keyDump();
} }
void KeyManagementWindow::exitApplication()
{
this->hide();
}
+2
View File
@@ -28,6 +28,7 @@ public:
private slots: private slots:
void test(); void test();
void generation(); void generation();
void exitApplication();
private: private:
unique_ptr<QHBoxLayout> hBox; unique_ptr<QHBoxLayout> hBox;
unique_ptr<QHBoxLayout> hBox2; unique_ptr<QHBoxLayout> hBox2;
@@ -35,6 +36,7 @@ private:
unique_ptr<QComboBox> comboBoxOfKeys; unique_ptr<QComboBox> comboBoxOfKeys;
unique_ptr<QLineEdit> valueOfKey; unique_ptr<QLineEdit> valueOfKey;
unique_ptr<QPushButton> generateNewDefaultKeys; unique_ptr<QPushButton> generateNewDefaultKeys;
unique_ptr<QPushButton> closeButton;
const int windowWidth{400}; const int windowWidth{400};
const int windowHeight{400}; const int windowHeight{400};
}; };
+6 -10
View File
@@ -1,22 +1,21 @@
#include<QtGui>
#include<QString> #include<QString>
#include<QIcon> #include<QIcon>
#include<iostream>
#include<memory>
#include"MessagingControls.h" #include"MessagingControls.h"
#include"KeyManagementWindow.h"
#include"Encryption.h" #include"Encryption.h"
#include"Decryption.h" #include"Decryption.h"
#include"KeyRetrieval.h" #include"KeyRetrieval.h"
MessagingControls::MessagingControls() MessagingControls::MessagingControls()
{ {
mainWindowWidth = 450;
mainWindowHeight = 450;
setupMainWindow(); setupMainWindow();
} }
void MessagingControls::setupMainWindow() void MessagingControls::setupMainWindow()
{ {
kh = unique_ptr<KeyManagementWindow>{new KeyManagementWindow};
textForCryption = unique_ptr<QTextEdit>{new QTextEdit{}}; textForCryption = unique_ptr<QTextEdit>{new QTextEdit{}};
cryptionButon = unique_ptr<QPushButton>{new QPushButton(tr("XO"))}; cryptionButon = unique_ptr<QPushButton>{new QPushButton(tr("XO"))};
cryptionSwitch = unique_ptr<QPushButton>{new QPushButton(tr("encrypt chosen"))}; cryptionSwitch = unique_ptr<QPushButton>{new QPushButton(tr("encrypt chosen"))};
@@ -41,7 +40,7 @@ void MessagingControls::setupMainWindow()
createMenus(); createMenus();
QObject::connect(closeApplication.get(), SIGNAL(triggered()), this, SLOT(close())); QObject::connect(closeApplication.get(), SIGNAL(triggered()), this, SLOT(exitApplication()));
QObject::connect(cryptionSwitch.get(), SIGNAL(clicked()), this, SLOT(changeCryptionType())); QObject::connect(cryptionSwitch.get(), SIGNAL(clicked()), this, SLOT(changeCryptionType()));
QObject::connect(cryptionButon.get(), SIGNAL(clicked()), this, SLOT(determineCryption())); QObject::connect(cryptionButon.get(), SIGNAL(clicked()), this, SLOT(determineCryption()));
QObject::connect(keyEdit.get(), SIGNAL(triggered()), this, SLOT(keyManagementWindow())); QObject::connect(keyEdit.get(), SIGNAL(triggered()), this, SLOT(keyManagementWindow()));
@@ -94,11 +93,8 @@ void MessagingControls::determineCryption()
cryptionChoice = true; cryptionChoice = true;
} }
} }
void MessagingControls::keyManagementWindow() void MessagingControls::keyManagementWindow() { kh.get()->show(); }
{ void MessagingControls::exitApplication() { exit(0); }
kh = unique_ptr<KeyManagementWindow>{new KeyManagementWindow};
kh.get()->show();
}
std::string MessagingControls::grabCryptionText() std::string MessagingControls::grabCryptionText()
+4 -13
View File
@@ -13,19 +13,9 @@
#include<QVBoxLayout> #include<QVBoxLayout>
#include<QDockWidget> #include<QDockWidget>
#include<QWidget> #include<QWidget>
#include<QString>
#include<memory> #include<memory>
#include"KeyManagementWindow.h" #include"KeyManagementWindow.h"
class QLabel;
class QLineEdit;
class QTextEdit;
class QPushButton;
class QMenuBar;
class QMainWindow;
class QMenu;
class QAction;
class QString;
using std::unique_ptr; using std::unique_ptr;
@@ -41,6 +31,7 @@ private slots:
void changeCryptionType(); void changeCryptionType();
void determineCryption(); void determineCryption();
void keyManagementWindow(); void keyManagementWindow();
void exitApplication();
private: private:
void setupMainWindow(); void setupMainWindow();
void createMenus(); void createMenus();
@@ -70,9 +61,9 @@ private:
std::string grabCryptionText(); std::string grabCryptionText();
int mainWindowHeight{450}; int mainWindowHeight;
int mainWindowWidth{550}; int mainWindowWidth;
bool cryptionChoice{true}; bool cryptionChoice;
}; };
#endif #endif