Last active
July 2, 2019 13:50
-
-
Save zenlinux/845d7f4d26b6327ff653691f27221502 to your computer and use it in GitHub Desktop.
Qt5 Gui program compiles but generates segmentation fault.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* file : hbsplitter.cpp */ | |
#include <QHBoxLayout> | |
#include <QSplitter> | |
#include <QString> | |
#include "hbsplitter.h" | |
#include "mlabelwidget.h" | |
#include "mtextedit.h" | |
Hbsplitter::Hbsplitter(QWidget *parent) : QWidget(parent) | |
{ | |
QHBoxLayout *hbox = new QHBoxLayout(this); | |
QSplitter *splitter1 = new QSplitter(Qt::Horizontal); | |
Mtextedit *myMtextedit = new Mtextedit(); | |
Mlabelwidget *myMlabelwidget = new Mlabelwidget(); | |
QString newLabel; | |
newLabel = "Qt with cpp."; | |
myMlabelwidget->show(); | |
myMlabelwidget->changeText(newLabel); | |
/* if I uncomment the above line I get "zsh: segmentation fault ./stage3" | |
* where stage3 is the name of the executable */ | |
splitter1->addWidget(myMtextedit); | |
splitter1->addWidget(myMlabelwidget); | |
hbox->addWidget(splitter1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* file : hbsplitter.h */ | |
#pragma once | |
#include <QWidget> | |
class Hbsplitter : public QWidget | |
{ | |
public: | |
Hbsplitter(QWidget *parent = 0); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* file : main.cpp */ | |
#include <QApplication> | |
#include "hbsplitter.h" | |
int main(int argc, char *argv[]) | |
{ | |
QApplication app(argc, argv); | |
app.setStyleSheet("QSplitter::handle { background-color: #333;}"); | |
Hbsplitter window; | |
window.resize(700, 300); | |
window.setWindowTitle("Notes to SVG"); | |
window.show(); | |
return app.exec(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* file : mlabelwidget.cpp */ | |
#include <QWidget> | |
#include <QHBoxLayout> | |
#include <QLabel> | |
#include <iostream> | |
#include "mlabelwidget.h" | |
Mlabelwidget::Mlabelwidget(QWidget *parent) : QWidget(parent) | |
{ | |
QHBoxLayout *hbox = new QHBoxLayout(this); | |
QLabel *label = new QLabel(); | |
label->setText("This is Qt"); | |
hbox->addWidget(label); | |
} | |
void Mlabelwidget::changeText(QString input) { | |
std::cout << "Mlabelwidget::changeText() called." << "\n"; | |
/* std::cout << input << "\n"; */ | |
label->setText(input); | |
std::cout << "Mlabelwidget::changeText() completed." << "\n"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* file : mlabelwidget.h */ | |
#pragma once | |
#include <QWidget> | |
#include <QLabel> | |
class Mlabelwidget : public QWidget | |
{ | |
public: | |
Mlabelwidget(QWidget *parent = 0); | |
QLabel *label; | |
void changeText(QString input); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* file : mtextedit.cpp */ | |
#include <QWidget> | |
#include <QHBoxLayout> | |
#include <QTextEdit> | |
#include "mtextedit.h" | |
Mtextedit::Mtextedit(QWidget *parent) : QWidget(parent) | |
{ | |
QHBoxLayout *hbox = new QHBoxLayout(this); | |
QTextEdit *mtextedit = new QTextEdit(); | |
hbox->addWidget(mtextedit); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* file : mtextedit.h */ | |
#pragma once | |
#include <QWidget> | |
class Mtextedit : public QWidget | |
{ | |
public: | |
Mtextedit(QWidget *parent = 0); | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###################################################################### | |
# Automatically generated by qmake (3.0) Tue Jul 2 04:42:55 2019 | |
###################################################################### | |
TEMPLATE = app | |
TARGET = stage3 | |
INCLUDEPATH += . | |
# Input | |
HEADERS += hbsplitter.h mlabelwidget.h mtextedit.h | |
SOURCES += hbsplitter.cpp main.cpp mlabelwidget.cpp mtextedit.cpp | |
QT += widgets svg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment