Hi, I created my own widget and when I'm trying to set something inside - Qt always crash. Do you know where is the problem?
main.cpp
...
MyWidget *w1 = new MyWidget();
w1->setText(text); //this always cause crash
MyWidget *w1 = new MyWidget();
QString text = "text";
w1->setText(text); //this always cause crash
To copy to clipboard, switch view to plain text mode
mywidget.h
#ifndef MYWIDGET_H
#define MYWIDGET_H
#include <QWidget>
#include <QLabel>
#include <QGridLayout>
{
Q_OBJECT
public:
explicit MyWidget
(QWidget *parent
= 0);
signals:
public slots:
private:
};
#ifndef MYWIDGET_H
#define MYWIDGET_H
#include <QWidget>
#include <QLabel>
#include <QGridLayout>
class MyWidget : public QWidget
{
Q_OBJECT
public:
explicit MyWidget(QWidget *parent = 0);
void SetText(QString text);
signals:
public slots:
private:
QLabel *label1;
};
To copy to clipboard, switch view to plain text mode
mywidget.cpp
include "mywidget.h"
MyWidget
::MyWidget(QWidget *parent
) :{
layout->addWidget(label1, 0, 0);
setLayout(layout);
}
void MyWidget
::setText(QString text
) { label1->setText(text);
}
include "mywidget.h"
MyWidget::MyWidget(QWidget *parent) :
QWidget(parent)
{
QGridLayout *layout = new QGridLayout();
QLabel *label1 = new QLabel("Name");
layout->addWidget(label1, 0, 0);
setLayout(layout);
}
void MyWidget::setText(QString text) {
label1->setText(text);
}
To copy to clipboard, switch view to plain text mode
Bookmarks