[SOLVED] Label overflow?



  • Hello

    Currently there happend something strange while I created a new class. There I added to the Header 3 QLabel's and a QGridLayout like this:

    @private:

    QLabel *first;
    QLabel *second;
    QLabel *third;
    
    QGridLayout *gridLayout;@
    

    Then I instance and added them in the source file to the layout, like:

    @
    first = new QLabel("first");
    second = new QLabel("second");
    third = new QLabel("third");

    gridLayout = new QGridLayout;
    gridLayout->addWidget(first, 0, 0);
    gridLayout->addWidget(second, 1, 0);
    gridLayout->addWidget(third, 2, 0);
    
    setLayout(gridLayout);@
    

    Then I creat from this class a Widget in the QMainWindow. Now, as I set this Widget show(), I get a runtime error. Curiously to say, if I add just two Labels, it works, from three Labels on I get this error. The other part is, if I define the QLabel's direclty in the source file like @QLabel *first = New QLabel("first")@ it works as well, what could cause this?



  • I don't see any problems in your code. Could you elaborate this part a little bit?

    [quote author="luggi" date="1306942242"]
    Then I creat from this class a Widget in the QMainWindow. Now, as I set this Widget show(), I get a runtime error.
    [/quote]

    How are you using the widget in QMainWindow? What is the error message?



  • Just a guess: perhaps you should set the size of the grid to be big enough so you actually have 3 columns?



  • The widget is used in the QMainWindow like this.

    In the header:

    @private:
    MyWidget *myWidget;@

    In the source file:

    @ myWidget = new myWidget;
    connect(aPushButton, SIGNAL(clicked()), myWidget, SLOT(show()));@

    Everytime I click on this Button, the application freezes totally and Windows 7 is searching for a solution of this problem. The Qt Creator gives me the exit code -1073741819. I was searching a bit around this code and found something about access violation in windows.

    @Andre: How can I set the size of the grid? I just found to set the height or width of a row or column.



  • Maybe error occurs in another place :)
    The grid will resize automatically by itself. So you don't need to worry about it.



  • Okey, there are some news. If I set this class in the QMainWindow public like
    @public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

    MyWidget *myWidget;@
    

    then it works. But I don't get why I get problems if the class is private?



  • Now it's time to close this thread, as I set the class back to private, just to try it a second time which I think is still necessary in windows, it worked! :-/


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.