Results 1 to 10 of 10

Thread: how to define structure inside hash?

  1. #1
    Join Date
    Oct 2011
    Posts
    160
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    31

    Default how to define structure inside hash?

    Hi is it possible to define a hash function with a structure inside it?
    I tried to define as shown below,....
    But getting link error saying..."exited with code -1073741819"

    Qt Code:
    1. class FilterColl : public QDialog
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. struct StructCheckedEntries {
    7. QString filename;
    8. QCheckBox *checkbox;
    9. QComboBox *combobox;
    10. QLineEdit *lineedit;
    11. };
    12. QHash<QString,StructCheckedEntries *> HCheckedEntries;
    13.  
    14.  
    15. private:
    16. Ui::FilterColl *ui;
    17. StructCheckedEntries *structentry;
    18. };
    To copy to clipboard, switch view to plain text mode 


    Please tell me whats the mistake here?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: how to define structure inside hash?

    Yes, it's possible. Is it really a linker error (meaning that the linker crashes) or rather an execution error (meaning that your program crashes)?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2011
    Posts
    160
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    31

    Default Re: how to define structure inside hash?

    Quote Originally Posted by wysota View Post
    Yes, it's possible. Is it really a linker error (meaning that the linker crashes) or rather an execution error (meaning that your program crashes)?
    When i ran the program.....nothing is displayed...evn mainwindow not opened....and after few seconds, got message as shown below....


    The program has unexpectedly finished.
    C:\Users\aurora\trial#3\singleFile-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug\release\singleFile.exe exited with code -1073741819

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: how to define structure inside hash?

    Ok, so it is your program that is crashing and not that you are getting a "link error". Most likely you are referencing an uninitialized pointer somewhere in your code. This is strictly a C++ issue that has nothing to do with your Qt problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    aurora (1st February 2012)

  6. #5
    Join Date
    Oct 2011
    Posts
    160
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    31

    Default Re: how to define structure inside hash?

    ok thank u wysota...
    i will try to find out that....
    Last edited by aurora; 1st February 2012 at 08:46.

  7. #6
    Join Date
    Jan 2012
    Posts
    17
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 3 Times in 3 Posts

    Default Re: how to define structure inside hash?

    I don't see any error in your declaration
    is possible that there are something strange in your code?
    could you copy some of it?

  8. #7
    Join Date
    Apr 2011
    Location
    Russia
    Posts
    85
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2
    Thanked 13 Times in 13 Posts

    Default Re: how to define structure inside hash?

    In *.h file:
    Qt Code:
    1. struct StructCheckedEntries
    2. {
    3. StructCheckedEntries():
    4. filename(""),
    5. checkbox(0),
    6. combobox(0),
    7. lineedit(0)
    8. {
    9. checkbox = new QCheckBox;
    10. combobox = new QComboBox;
    11. lineedit = new QLineEdit;
    12. }
    13.  
    14. inline void Free()
    15. {
    16. if (checkbox)
    17. {
    18. delete checkbox;
    19. checkbox = 0;
    20. }
    21.  
    22. if (combobox)
    23. {
    24. delete combobox;
    25. combobox = 0;
    26. }
    27.  
    28. if (lineedit)
    29. {
    30. delete lineedit;
    31. lineedit = 0;
    32. }
    33. }
    34.  
    35. QString filename;
    36. QCheckBox *checkbox;
    37. QComboBox *combobox;
    38. QLineEdit *lineedit;
    39. };
    40.  
    41. QHash<QString,StructCheckedEntries *> HCheckedEntries;
    To copy to clipboard, switch view to plain text mode 

    In *.cpp file:
    Qt Code:
    1. StructCheckedEntries entr;
    2. entr.filename = "fileName";
    3. entr.checkbox->setText("checkbox");
    4. entr.combobox->addItem("combobox");
    5. entr.lineedit->setText("lineedit");
    6.  
    7. HCheckedEntries.insert( "123", &entr );
    8.  
    9. StructCheckedEntries *pentr = HCheckedEntries.value("123");
    10.  
    11. qDebug() << "FileName: " << pentr->filename;
    12. qDebug() << "ComboBox: " << pentr->combobox->itemText(0);
    13. qDebug() << "LineEdit: " << pentr->lineedit->text();
    14.  
    15. if (pentr->checkbox->checkState() & Qt::Checked)
    16. qDebug() << "Checked";
    17. else
    18. qDebug() << "Unchecked";
    To copy to clipboard, switch view to plain text mode 

    To delete use pentr->Free();
    Last edited by Jonny174; 1st February 2012 at 10:51.

  9. The following user says thank you to Jonny174 for this useful post:

    aurora (1st February 2012)

  10. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: how to define structure inside hash?

    Do you initialize StructCheckedEntries and its checkbox, combobox and lineedit members anywhere?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #9
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 106 Times in 103 Posts

    Default Re: how to define structure inside hash?

    I'm guessing you call Free() twice somewhere, and as you do not null the pointers you get crash when you try to delete already deleted pointer.
    Qt Code:
    1. inline void Free()
    2. {
    3. if(checkbox)
    4. { // good coding practice: use brackets
    5. delete checkbox;
    6. checkbox = NULL; // good coding practice: always null deleted pointers
    7. // do that otherwise the check above will always be true even after you've deleted the object
    8. }
    9.  
    10. if (combobox)
    11. { // good coding practice: use brackets
    12. delete combobox;
    13. combobox= NULL; // good coding practice: always null deleted pointers
    14. // do that otherwise the check above will always be true even after you've deleted the object
    15. }
    16. if (lineedit)
    17. { // good coding practice: use brackets
    18. delete lineedit;
    19. lineedit= NULL; // good coding practice: always null deleted pointers
    20. // do that otherwise the check above will always be true even after you've deleted the object
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 
    btw debugging the code should give you an answer as well.

  12. The following user says thank you to Spitfire for this useful post:

    aurora (1st February 2012)

  13. #10
    Join Date
    Oct 2011
    Posts
    160
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    31

    Default Re: how to define structure inside hash?

    Thank u all...
    I did it....
    Thank u so much....

Similar Threads

  1. How to get sha1 hash
    By lyuts in forum Qt Programming
    Replies: 3
    Last Post: 15th February 2012, 15:35
  2. Replies: 3
    Last Post: 15th July 2011, 20:43
  3. Replies: 12
    Last Post: 26th June 2011, 11:26
  4. Hash a file with QT
    By manekineko in forum Qt Programming
    Replies: 5
    Last Post: 21st April 2010, 06:55
  5. Are there functions to make md5 hash
    By learning_qt in forum Qt Programming
    Replies: 8
    Last Post: 22nd July 2009, 04:21

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
  •  
Qt is a trademark of The Qt Company.