Results 1 to 11 of 11

Thread: QHash compile error

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: QHash compile error

    hash.insert(1, comboBox_1);
    hash.insert(2, comboBox_2);
    hash.insert(3, comboBox_3);
    But you cannot do this in the header, in the class declaration.
    It has to be in a function.

    Regards

  2. #2
    Join Date
    Aug 2007
    Posts
    244
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    42
    Thanked 8 Times in 8 Posts

    Default Re: QHash compile error

    You're right; now the program compiles but there is a segmentation fault during execution; here the cpp file:

    Qt Code:
    1. #include <QtGui>
    2. #include "maindialog.h"
    3.  
    4. MainDialog::MainDialog(QWidget *parent)
    5. : QDialog(parent)
    6. {
    7. hash.insert(1, comboBox_1);
    8. hash.insert(2, comboBox_2);
    9. hash.insert(3, comboBox_3);
    10.  
    11. comboBox_1 = new QComboBox;
    12. comboBox_2 = new QComboBox;
    13. comboBox_3 = new QComboBox;
    14.  
    15. for(int i = 1; i < 4; i++)
    16. for(int j = 0; j < 4; j++)
    17. hash.value(i)->addItem("New Entry");
    18.  
    19. QVBoxLayout mainLayout;
    20. mainLayout.addWidget(comboBox_1);
    21. mainLayout.addWidget(comboBox_2);
    22. mainLayout.addWidget(comboBox_3);
    23. }
    To copy to clipboard, switch view to plain text mode 

    The problem seems the line using hash member.

    Bye
    Giuseppe CalÃ

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: QHash compile error

    You have to instantiate the combos BEFORE adding them to the hash.

    Regards

  4. #4
    Join Date
    Aug 2007
    Posts
    244
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    42
    Thanked 8 Times in 8 Posts

    Default Re: QHash compile error

    Ops, you're again right.

    Thanks
    Giuseppe CalÃ

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    22
    Thanked 19 Times in 16 Posts

    Default Re: QHash compile error

    you also should create the layout with new instead of using an object that dies when it reaches the end of the scope of the constructor.

Similar Threads

  1. Qtopia core 4.2.2 cross compile make error
    By smiyai18 in forum Installation and Deployment
    Replies: 2
    Last Post: 28th August 2007, 17:04
  2. qt 4.2.2 install on aix
    By try to remember in forum Installation and Deployment
    Replies: 2
    Last Post: 28th March 2007, 12:19
  3. Qt-x11-commercial-src-4.2.0-snapshot-20060824 error
    By DevObject in forum Installation and Deployment
    Replies: 4
    Last Post: 24th August 2006, 23:31
  4. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52
  5. Am I the only one with "make" error ?
    By probine in forum Installation and Deployment
    Replies: 1
    Last Post: 13th February 2006, 12:54

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.