PDA

View Full Version : Adding new variable into header file breaks my application



Raadush
26th July 2012, 14:20
Hi, I have this issue. I have header file which looks like this:



#ifndef CARDMANAGERMD_H
#define CARDMANAGERMD_H

#ifdef __APPLE__
#define IMG_PATH "/Applications/Card Manager EIDCze.app/Contents/Resources/"
#elif __unix
#define IMG_PATH "/usr/local/share/crplus-cm-eidcze/"
#endif

#include <QtGui>
#include "pkcs11manipulatorMD.h"
#include "messages.h"
#include <QApplication>
#include <QDesktopWidget>
#include <QTranslator>
#include <QListData>
#include <QWebView>
#include <QHostInfo>
#include <stdlib.h>

#define H_SPRAVCE 0
#define H_READER 1
#define H_CARD 2
#define H_KEY 3
#define H_CERTIFICATE 4
#define H_CSPPARAM 5
#define H_SOLUTIONS 6
#define H_DATA 7
#define H_DIAG 8

#define M_FILE_CHANGEPIN 0
#define M_FILE_CHANGEPUK 1
#define M_FILE_UNBLOCKPIN 2
#define M_FILE_FORGETPIN 3
#define M_FILE_READINFO 4
#define M_FILE_DEFRAGCARD 5
#define M_CERT_DETAIL 6
#define M_CERT_EXPORT 7
#define M_CERT_IMPORTFILE 8
#define M_CERT_DELETE 9
#define M_KEY_EXPORT 10
#define M_KEY_IMPORT 11
#define M_KEY_TEST 12
#define M_KEY_DELETE 13
#define M_DATA_EXPORT 14
#define M_DATA_IMPORT 15
#define M_DATA_ACTUAL 16
#define M_DATA_READVALUE 17
#define M_DATA_DELETE 18

#define T_TEXT 0
#define T_DATA 1

class CardManager : public QMainWindow
{
Q_OBJECT

private:
bool firstTime;
bool reloadBool;
bool libraryLoaded;

int containerCount;
int readerSelected;
int containerSelected;
int dataObjectSelected;

QString *allPrivateData;
QString *maxPrivateData;
QString *leakPrivateData;

QString pinResetDay;
QString pinResetAt;
QTimer *mainTimer;
QTimer *countdownTimer;
QComboBox *cspLanguageW;
QLineEdit *cspTimeoutW;
QCheckBox *cspAnimationW;
QCheckBox *cspRememberPinW;
QLineEdit *cspLimitPinW;

QList<QString> readers;
QList<QString> vendors;
QList<bool> sCardConnects;
QList<QString> *containers;
QList<key_info> *keys;
QList<int> *certificates;
QList<QString> *dataObjects;

QList<bool> readerConnects;
QList<bool> readerUsbs;
QList<QString> readerVendors;
QList<QString> readerTypes;
QList<QString> readerPorts;
QList<int> cardRoots;
QList<int> cardValidCerts;

QList<int> *hardwareGenerated;
QList<int> *signsAllowed;
QList<int> *decryptsAllowed;
QList<bool> *isCA;
QString solutions;
QString diag;
QString defaultCspText;
bool reloaded;
bool canceled;

QString *pin;
QString *pinForChange;
QString *resetedPin;
QString *puk;
bool *wrongPinCounter;

QProgressDialog* progress;
QMenu *fileMenu;
QMenu *viewMenu;
QMenu *certificateMenu;
QMenu *keyMenu;
//QMenu *dataMenu;
QMenu *helpMenu;
QWidget *infoArea;
QWidget *centWidget;
QTreeWidget *navigator;
QHBoxLayout *mainLayout;
QVBoxLayout *infoLayout;
QStatusBar *statusBar;
QLabel *statusBarText;
QWebView *infoHtml;
QSplitter *splitter;
QScrollArea *scrollArea;

QAction *versionAction;
QAction *changePinAction;
QAction *changePukAction;
QAction *unblockPinAction;
QAction *showDiagAction;
QAction *saveDiagAction;
QAction *printAction;
QAction *printSetupAction;
QAction *expertModeAction;
QAction *exitAction;
QAction *reloadAction;
QAction *statusbarAction;
QAction *detailCertAction;
QAction *exportCertAction;
QAction *importCfromFileAction;
QAction *deleteCAction;
QAction *exportKeyAction;
QAction *importKeyAction;
QAction *testKeyAction;
QAction *deleteKAction;
//QAction *exportDataAction;
//QAction *importDataAction;
//QAction *deleteDataAction;
QAction *suggestAction;
QAction *contentsAction;
QAction *aboutAction;

QPrinter *printer;
QPageSetupDialog *pageSetup;

X509Cert *cert;
X509Viewer *viewer;

unsigned long *sCardConnected;
QMessageBox *message;
QInputDialog *input;

int initializeTree();
void initializeArea();
void waitForProgress();
void generateHeader(int type);
void generateCopyright();
void menuAllows(QList<int> items);
int verifyPin(int readerNumber);
int verifyPuk(int readerNumber);

QString libVersion;
QString language;
QString *diagToSave;
QString *diagCardToSave;
QString diagKeyToSave[128];

bool eventFilter( QObject* o, QEvent* e );
public:
QMainWindow mainWindow;
Pkcs11Manipulator *p11manipulator;
bool isLoaded();
QString readHtml(QString filename);

CardManager(QWidget *parent = 0);
~CardManager();

private slots:
void quit();
void treeClicked(QTreeWidgetItem *item);
void activatedLink(const QUrl &link);
void version();
void changePin();
void changePuk();
void unblockPin();
void reload();
void statusbarOnOff();
void importCert();
void exportCert();
void showCertview();
void importKey();
void exportKey();
void testKey();
void deleteObject();
void suggestSolutions();
void showDiag();
void saveDiag();
void print();
void printSetup();
void expertMode();
void about();
void checkPinLength(const QString &text);
};

#endif // CARDMANAGER_H


Now everything works fine. But I wanted to add new menu item, so I added those commented variables. But if I uncomment even one of these (for example QMenu *dataMenu), my application stops working. They are not even used anywhere in cpp file, just declared in header. When I run my application after declaring one of these variables, there is no error, constructor of CardManager class creates everything (I have log on last line of constructor), but application frame never shows up. Why is that? If I declare those variables locally in constructor inside cpp file, everything works fine, but I need them global.

high_flyer
26th July 2012, 14:42
try clean and rebuild.

Raadush
26th July 2012, 14:51
Tried that couple of times, even tried to build into new folder. Nothing helped.

high_flyer
26th July 2012, 16:26
run the application in a debugger - where does it crash?

amleto
26th July 2012, 16:37
show compilable example. What you are posting is very unlikely to be the fault. Your code is probably tripping over some other undefined behaviour.

Raadush
27th July 2012, 07:50
Wiseguy: it doesn't crash. In my main:


CardManager cardManager;

if(cardManager.isLoaded())
{
cardManager.mainWindow.show();
app.exec();
}


when I have commented those 4 lines in header file, when debugger hits app.exec(), mainWindow of cardManager is shown. When I uncomment one of those commented lines, when it hits app.exec() nothing happens, no mainWindow is shown the application only get stuck in exec() loop and I must close it usind stop button.

amleto: Yes, what I'm posting is not fault, but as I said there are 4 commented lines in that code and when I uncoment one of them (define one new QMenu or QAction variable) my app stops working. I dont have used them anywhere else in my code except this definition.

high_flyer
27th July 2012, 10:01
Post your full code.
What do you mean by "stopped working"?

amleto
27th July 2012, 11:04
show compilable example. What you are posting is very unlikely to be the fault. Your code is probably tripping over some other undefined behaviour.



amleto: Yes, what I'm posting is not fault, but as I said there are 4 commented lines in that code and when I uncoment one of them (define one new QMenu or QAction variable) my app stops working. I dont have used them anywhere else in my code except this definition.

I'll repeat.

show compilable example.

Oh yeah, and it's in my sig too.

d_stranz
29th July 2012, 01:28
@Raadush: I put on my magic wizard hat, which allows me to see invisible code. My friends high_flyer and amleto don't have a hat like this one, so they are at a disadvantage.

You have about 300 member variables in your class. Are you initializing every one of them to some known, acceptable value in your constructor - especially those QList<int> * ones? Or are you just hoping that when you use one of them it will magically (like my hat) have a good enough value that Qt can do something with it?

Are you confusing QList<int> * with QList<int *> and using one when you mean the other? Likewise with the QString * member variables. What's the point of a pointer to a QString?