Last active
August 19, 2017 02:55
-
-
Save eyllanesc/11ae5d8b07c6c4b9bd0c0ef52ed4335e to your computer and use it in GitHub Desktop.
Test
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
#include "boot.h" | |
#include <QCoreApplication> | |
#include <QDebug> | |
#include <QThread> | |
#include <QTimer> | |
Boot::Boot(QObject *parent) : QObject(parent) | |
{ | |
} | |
void Boot::load() | |
{ | |
loadXMLContent(); | |
} | |
QString Boot::errorMsg() | |
{ | |
return m_errorMsg; | |
} | |
void Boot::setErrorMsg(const QString &errorMsg) | |
{ | |
if(m_errorMsg == errorMsg) | |
return; | |
m_errorMsg = errorMsg; | |
emit errorMsgChanged(); | |
} | |
QString Boot::xmlContent() | |
{ | |
return m_xmlContent; | |
} | |
void Boot::setXmlContent(const QString &xmlContent) | |
{ | |
if(m_xmlContent == xmlContent) | |
return; | |
m_xmlContent = xmlContent; | |
emit xmlContentChanged(); | |
} | |
bool Boot::loadXMLContent() | |
{ | |
bool res; | |
timer = new QTimer(this); | |
setErrorMsg("Parsing channels.xml"); | |
setErrorMsg("Trying to open channels.xml"); | |
channelsList.open("config/channels.xml"); | |
if(!channelsList.is_open()) | |
{ | |
setErrorMsg("There was an error opening channels.xml"); | |
res = false; | |
} | |
else | |
{ | |
setErrorMsg("channels.xml was opened successfully"); | |
setErrorMsg("now reading from channels.xml"); | |
connect(timer, &QTimer::timeout, [this](){ | |
if(!channelsList.eof()) | |
{ | |
std::string temp; | |
getline(channelsList, temp); | |
QString qTemp = QString::fromStdString(temp); | |
setErrorMsg("Parsing " +qTemp); | |
tempXMLContent += qTemp+"\n"; | |
} | |
else{ | |
setXmlContent(tempXMLContent); | |
setErrorMsg("Parsing is complete"); | |
} | |
}); | |
timer->start(10); | |
res = true; | |
} | |
return res; | |
} |
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
#ifndef BOOT_H | |
#define BOOT_H | |
#include <QObject> | |
#include <fstream> | |
class QTimer; | |
class Boot : public QObject | |
{ | |
Q_OBJECT | |
Q_PROPERTY(QString errorMsg READ errorMsg NOTIFY errorMsgChanged) | |
Q_PROPERTY(QString xmlContent READ xmlContent NOTIFY xmlContentChanged) | |
public: | |
explicit Boot(QObject *parent = nullptr); | |
Q_INVOKABLE void load(); | |
bool loadXMLContent(); | |
QString errorMsg(); | |
void setErrorMsg(const QString &errorMsg); | |
QString xmlContent(); | |
void setXmlContent(const QString &xmlContent); | |
signals: | |
void errorMsgChanged(); | |
void xmlContentChanged(); | |
private: | |
QString m_errorMsg; | |
QString m_xmlContent; | |
QTimer *timer; | |
QString tempXMLContent; | |
std::ifstream channelsList; | |
}; | |
#endif // BOOT_H |
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
#include "boot.h" | |
#include <QGuiApplication> | |
#include <QQmlApplicationEngine> | |
#include <QQuickView> | |
#include <QQmlEngine> | |
int main(int argc, char *argv[]) | |
{ | |
QGuiApplication app(argc, argv); | |
QCoreApplication::setApplicationName("xyz"); | |
QCoreApplication::setAttribute(Qt::AA_X11InitThreads); | |
QQuickView quickView; | |
qmlRegisterType<Boot>("xyz", 1, 0, "Boot"); | |
quickView.setSource(QUrl(QStringLiteral("qrc:/main.qml"))); | |
quickView.setResizeMode(QQuickView::SizeRootObjectToView); | |
quickView.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
import QtQuick 2.0 | |
import "." | |
import QtQuick.XmlListModel 2.0 | |
import xyz 1.0 | |
Item{ | |
Timer { | |
id: timer | |
} | |
function delay(delayTime, cb) { | |
timer.interval = delayTime; | |
timer.repeat = false; | |
timer.triggered.connect(cb); | |
timer.start(); | |
} | |
Loader{ | |
id: bootPageLoader | |
anchors.fill:parent | |
sourceComponent: bootSystem | |
focus:true | |
} | |
Component{ | |
id:bootSystem | |
Rectangle{ | |
width: 640 | |
height: 480 | |
color:"black" | |
focus:true | |
Component.onCompleted: { | |
booting.load(); | |
} | |
Boot{ | |
id:booting | |
onErrorMsgChanged: { | |
console.log("New Boot Log Message: " + errorMsg); | |
//This is where I am adding to the listview every time I receive a signal | |
logModel.append({msg:errorMsg}); | |
log.positionViewAtEnd(); | |
} | |
} | |
ListView { | |
id:log | |
anchors.left: parent.left | |
anchors.leftMargin: 10 | |
anchors.topMargin: 10 | |
anchors.bottomMargin:10 | |
anchors.top: parent.top | |
width:(parent.width*40)/100 | |
height:parent.height-20 | |
model: ListModel{ | |
id:logModel | |
} | |
delegate: Text { | |
text: msg | |
color: "green" | |
font.pixelSize: 15 | |
} | |
} | |
Text{ | |
id: loading | |
anchors{ | |
horizontalCenter: parent.horizontalCenter | |
verticalCenter: parent.verticalCenter | |
} | |
text: "LOADING..." | |
color: "white" | |
font.pixelSize: Math.round(parent.height/20) | |
font.bold: true | |
} | |
} | |
} | |
} |
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
<RCC> | |
<qresource prefix="/"> | |
<file>main.qml</file> | |
</qresource> | |
</RCC> |
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
TEMPLATE = app | |
QT += qml quick | |
CONFIG += c++11 | |
SOURCES += main.cpp \ | |
boot.cpp | |
RESOURCES += qml.qrc | |
# Additional import path used to resolve QML modules in Qt Creator's code model | |
QML_IMPORT_PATH = | |
# Additional import path used to resolve QML modules just for Qt Quick Designer | |
QML_DESIGNER_IMPORT_PATH = | |
# The following define makes your compiler emit warnings if you use | |
# any feature of Qt which as been marked deprecated (the exact warnings | |
# depend on your compiler). Please consult the documentation of the | |
# deprecated API in order to know how to port your code away from it. | |
DEFINES += QT_DEPRECATED_WARNINGS | |
# You can also make your code fail to compile if you use deprecated APIs. | |
# In order to do so, uncomment the following line. | |
# You can also select to disable deprecated APIs only up to a certain version of Qt. | |
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 | |
# Default rules for deployment. | |
qnx: target.path = /tmp/$${TARGET}/bin | |
else: unix:!android: target.path = /opt/$${TARGET}/bin | |
!isEmpty(target.path): INSTALLS += target | |
HEADERS += \ | |
boot.h |
here is channels.xml
channels.xml
@Muhand For a few lines the effect is not visible as you have noticed, add more lines and you will see, if you want to be slower you can change the timer to a longer time.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What if I want to read a file? here is my code
`
bool Boot::loadXMLContent()
{
bool res;
ifstream channelsList;
QString tempXMLContent;
}`
This is the code of XmlContent
in boot.h add
Q_PROPERTY(QString xmlContent READ xmlContent NOTIFY xmlContentChanged)
QString xmlContent(); void setXmlContent(const QString &xmlContent);
void xmlContentChanged();
QString m_xmlContent;