Results 1 to 9 of 9

Thread: Adding new variable into header file breaks my application

  1. #1
    Join Date
    Apr 2012
    Posts
    43
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Adding new variable into header file breaks my application

    Hi, I have this issue. I have header file which looks like this:

    Qt Code:
    1. #ifndef CARDMANAGERMD_H
    2. #define CARDMANAGERMD_H
    3.  
    4. #ifdef __APPLE__
    5. #define IMG_PATH "/Applications/Card Manager EIDCze.app/Contents/Resources/"
    6. #elif __unix
    7. #define IMG_PATH "/usr/local/share/crplus-cm-eidcze/"
    8. #endif
    9.  
    10. #include <QtGui>
    11. #include "pkcs11manipulatorMD.h"
    12. #include "messages.h"
    13. #include <QApplication>
    14. #include <QDesktopWidget>
    15. #include <QTranslator>
    16. #include <QListData>
    17. #include <QWebView>
    18. #include <QHostInfo>
    19. #include <stdlib.h>
    20.  
    21. #define H_SPRAVCE 0
    22. #define H_READER 1
    23. #define H_CARD 2
    24. #define H_KEY 3
    25. #define H_CERTIFICATE 4
    26. #define H_CSPPARAM 5
    27. #define H_SOLUTIONS 6
    28. #define H_DATA 7
    29. #define H_DIAG 8
    30.  
    31. #define M_FILE_CHANGEPIN 0
    32. #define M_FILE_CHANGEPUK 1
    33. #define M_FILE_UNBLOCKPIN 2
    34. #define M_FILE_FORGETPIN 3
    35. #define M_FILE_READINFO 4
    36. #define M_FILE_DEFRAGCARD 5
    37. #define M_CERT_DETAIL 6
    38. #define M_CERT_EXPORT 7
    39. #define M_CERT_IMPORTFILE 8
    40. #define M_CERT_DELETE 9
    41. #define M_KEY_EXPORT 10
    42. #define M_KEY_IMPORT 11
    43. #define M_KEY_TEST 12
    44. #define M_KEY_DELETE 13
    45. #define M_DATA_EXPORT 14
    46. #define M_DATA_IMPORT 15
    47. #define M_DATA_ACTUAL 16
    48. #define M_DATA_READVALUE 17
    49. #define M_DATA_DELETE 18
    50.  
    51. #define T_TEXT 0
    52. #define T_DATA 1
    53.  
    54. class CardManager : public QMainWindow
    55. {
    56. Q_OBJECT
    57.  
    58. private:
    59. bool firstTime;
    60. bool reloadBool;
    61. bool libraryLoaded;
    62.  
    63. int containerCount;
    64. int readerSelected;
    65. int containerSelected;
    66. int dataObjectSelected;
    67.  
    68. QString *allPrivateData;
    69. QString *maxPrivateData;
    70. QString *leakPrivateData;
    71.  
    72. QString pinResetDay;
    73. QString pinResetAt;
    74. QTimer *mainTimer;
    75. QTimer *countdownTimer;
    76. QComboBox *cspLanguageW;
    77. QLineEdit *cspTimeoutW;
    78. QCheckBox *cspAnimationW;
    79. QCheckBox *cspRememberPinW;
    80. QLineEdit *cspLimitPinW;
    81.  
    82. QList<QString> readers;
    83. QList<QString> vendors;
    84. QList<bool> sCardConnects;
    85. QList<QString> *containers;
    86. QList<key_info> *keys;
    87. QList<int> *certificates;
    88. QList<QString> *dataObjects;
    89.  
    90. QList<bool> readerConnects;
    91. QList<bool> readerUsbs;
    92. QList<QString> readerVendors;
    93. QList<QString> readerTypes;
    94. QList<QString> readerPorts;
    95. QList<int> cardRoots;
    96. QList<int> cardValidCerts;
    97.  
    98. QList<int> *hardwareGenerated;
    99. QList<int> *signsAllowed;
    100. QList<int> *decryptsAllowed;
    101. QList<bool> *isCA;
    102. QString solutions;
    103. QString diag;
    104. QString defaultCspText;
    105. bool reloaded;
    106. bool canceled;
    107.  
    108. QString *pin;
    109. QString *pinForChange;
    110. QString *resetedPin;
    111. QString *puk;
    112. bool *wrongPinCounter;
    113.  
    114. QProgressDialog* progress;
    115. QMenu *fileMenu;
    116. QMenu *viewMenu;
    117. QMenu *certificateMenu;
    118. QMenu *keyMenu;
    119. //QMenu *dataMenu;
    120. QMenu *helpMenu;
    121. QWidget *infoArea;
    122. QWidget *centWidget;
    123. QTreeWidget *navigator;
    124. QHBoxLayout *mainLayout;
    125. QVBoxLayout *infoLayout;
    126. QStatusBar *statusBar;
    127. QLabel *statusBarText;
    128. QWebView *infoHtml;
    129. QSplitter *splitter;
    130. QScrollArea *scrollArea;
    131.  
    132. QAction *versionAction;
    133. QAction *changePinAction;
    134. QAction *changePukAction;
    135. QAction *unblockPinAction;
    136. QAction *showDiagAction;
    137. QAction *saveDiagAction;
    138. QAction *printAction;
    139. QAction *printSetupAction;
    140. QAction *expertModeAction;
    141. QAction *exitAction;
    142. QAction *reloadAction;
    143. QAction *statusbarAction;
    144. QAction *detailCertAction;
    145. QAction *exportCertAction;
    146. QAction *importCfromFileAction;
    147. QAction *deleteCAction;
    148. QAction *exportKeyAction;
    149. QAction *importKeyAction;
    150. QAction *testKeyAction;
    151. QAction *deleteKAction;
    152. //QAction *exportDataAction;
    153. //QAction *importDataAction;
    154. //QAction *deleteDataAction;
    155. QAction *suggestAction;
    156. QAction *contentsAction;
    157. QAction *aboutAction;
    158.  
    159. QPrinter *printer;
    160. QPageSetupDialog *pageSetup;
    161.  
    162. X509Cert *cert;
    163. X509Viewer *viewer;
    164.  
    165. unsigned long *sCardConnected;
    166. QMessageBox *message;
    167. QInputDialog *input;
    168.  
    169. int initializeTree();
    170. void initializeArea();
    171. void waitForProgress();
    172. void generateHeader(int type);
    173. void generateCopyright();
    174. void menuAllows(QList<int> items);
    175. int verifyPin(int readerNumber);
    176. int verifyPuk(int readerNumber);
    177.  
    178. QString libVersion;
    179. QString language;
    180. QString *diagToSave;
    181. QString *diagCardToSave;
    182. QString diagKeyToSave[128];
    183.  
    184. bool eventFilter( QObject* o, QEvent* e );
    185. public:
    186. QMainWindow mainWindow;
    187. Pkcs11Manipulator *p11manipulator;
    188. bool isLoaded();
    189. QString readHtml(QString filename);
    190.  
    191. CardManager(QWidget *parent = 0);
    192. ~CardManager();
    193.  
    194. private slots:
    195. void quit();
    196. void treeClicked(QTreeWidgetItem *item);
    197. void activatedLink(const QUrl &link);
    198. void version();
    199. void changePin();
    200. void changePuk();
    201. void unblockPin();
    202. void reload();
    203. void statusbarOnOff();
    204. void importCert();
    205. void exportCert();
    206. void showCertview();
    207. void importKey();
    208. void exportKey();
    209. void testKey();
    210. void deleteObject();
    211. void suggestSolutions();
    212. void showDiag();
    213. void saveDiag();
    214. void print();
    215. void printSetup();
    216. void expertMode();
    217. void about();
    218. void checkPinLength(const QString &text);
    219. };
    220.  
    221. #endif // CARDMANAGER_H
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Adding new variable into header file breaks my application

    try clean and rebuild.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Apr 2012
    Posts
    43
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Adding new variable into header file breaks my application

    Tried that couple of times, even tried to build into new folder. Nothing helped.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Adding new variable into header file breaks my application

    run the application in a debugger - where does it crash?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Adding new variable into header file breaks my application

    show compilable example. What you are posting is very unlikely to be the fault. Your code is probably tripping over some other undefined behaviour.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  6. #6
    Join Date
    Apr 2012
    Posts
    43
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Adding new variable into header file breaks my application

    Wiseguy: it doesn't crash. In my main:
    Qt Code:
    1. CardManager cardManager;
    2.  
    3. if(cardManager.isLoaded())
    4. {
    5. cardManager.mainWindow.show();
    6. app.exec();
    7. }
    To copy to clipboard, switch view to plain text mode 

    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.

  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Adding new variable into header file breaks my application

    Post your full code.
    What do you mean by "stopped working"?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  8. #8
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Adding new variable into header file breaks my application

    Quote Originally Posted by amleto View Post
    show compilable example. What you are posting is very unlikely to be the fault. Your code is probably tripping over some other undefined behaviour.
    Quote Originally Posted by Raadush View Post
    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.
    Quote Originally Posted by amleto View Post
    show compilable example.
    Oh yeah, and it's in my sig too.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  9. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Adding new variable into header file breaks my application

    @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?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 2
    Last Post: 13th June 2011, 15:29
  2. adding image to header column of a table view
    By nageshvk in forum Qt Programming
    Replies: 1
    Last Post: 4th May 2011, 04:14
  3. Replies: 10
    Last Post: 6th April 2011, 10:05
  4. Adding a button in the header of a QTreeWidget
    By ioannis in forum Qt Programming
    Replies: 1
    Last Post: 25th September 2008, 18:06
  5. Replies: 2
    Last Post: 3rd April 2007, 19:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.