Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Assert uint(i) < uint(size()) in file qstring.h line 933
Forum Updated to NodeBB v4.3 + New Features

Assert uint(i) < uint(size()) in file qstring.h line 933

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 758 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cuteqq
    wrote on last edited by
    #1

    I am learning Qt and I copied this code from a book. The program did not compile and resulted in the error below:

    Desktop_Qt_5_11_1_MSVC2017_64bit-Debug\debug\RSS_Reader...
    QML debugging is enabled. Only use this in a safe environment.
    ASSERT: "uint(i) < uint(size())" in file c:\users\qt\work\qt\qtbase\src\corelib\tools\qstring.h, line 933
    

    I am attaching the files in the project, there is literally no code, just QML files. Please help !

    main.cpp

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QFont>
    
    int main(int argc, char *argv[])
    {
        QGuiApplication app(argc, argv);
    
    #ifdef Q_OS_WIN
        app.setFont(QFont(QString("Times New Roman")));
    #endif
    
        QQmlApplicationEngine engine;
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    
        return app.exec();
    }
    

    main.qml

    import QtQuick 2.3
    import QtQuick.Window 2.2
    import QtQuick.XmlListModel 2.0
    import QtQuick.Controls 1.2
    import QtQuick.Controls.Styles 1.2
    import "qrc:/"
    
    Window {
        id: mainWindow
        visible: true
        width: 720
        height: 400
        flags: Qt.Window | Qt.FramelessWindowHint
    
        TitleBar {
            id: titleBar
        }
    
        Text {
            id: windowTitle
            anchors { left: titleBar.left; leftMargin: 10; verticalCenter: titleBar.verticalCenter }
            text: "BBC News Reader"
            color: "#FFF"
            font.pointSize: 10
        }
    
        Feeds {
            id: categoriesModel
        }
    
        ListView {
            id: categories
    
            orientation: ListView.Vertical
            spacing: 3
            model:categoriesModel
            delegate: CategoriesDelegate {
                id: categoriesDelegate
                width: categories.width
            }
            property string currentUrl: categoriesModel.get(0).url
        }
    
        ScrollView {
            id: categoriesView
            contentItem: categories
            anchors { left: parent.left; top: titleBar.bottom; bottom: parent.bottom; }
            width: 0.2 * parent.width
            style: ScrollViewStyle {
                transientScrollBars: true
            }
        }
    
        XmlListModel {
            id: newsModel
    
            source: categories.currentUrl
            namespaceDeclarations: "declare namespace media = 'http://search.yahoo.com/mrss/'; declare namespace atom = 'http://www.w3.org/2005/Atom';"
            query: "/rss/channel/item"
    
            XmlRole { name: "title"; query: "title/string()" }
            XmlRole { name: "description"; query: "description/string()" }
            XmlRole { name: "link"; query: "link/string()" }
            XmlRole { name: "pubDate"; query: "pubDate/string()" }
            //XPath starts from 1 not 0 and the second thumbnail is larger and more clear
            XmlRole { name: "thumbnail"; query: "media:thumbnail[2]/@url/string()" }
        }
    
        ScrollView {
            id: newsView
            anchors { left: categoriesView.right; leftMargin: 10; right: parent.right; top: titleBar.bottom; bottom: parent.bottom }
            style: ScrollViewStyle {
                transientScrollBars: true
            }
            ListView {
                id: newsList
                model: newsModel
                delegate: NewsDelegate {
                    width: newsList.width
                }
            }
        }
    
        BusyIndicator {
            anchors.centerIn: newsView
            running: newsModel.status == XmlListModel.Loading
        }
    }
    
    

    CategoriesDelegate.qml

    import QtQuick 2.3
    
    Rectangle {
        id: delegate
        height: 80
    
        property bool selected: ListView.isCurrentItem
    
        Text {
            id: title
            anchors { left: parent.left; leftMargin: 10; right: parent.right; rightMargin: 10 }
            anchors.verticalCenter: delegate.verticalCenter
            text: name
            font { pointSize: 18; bold: true }
            verticalAlignment: Text.AlignVCenter
            wrapMode: Text.WordWrap
            scale: selected ? 1.0 : 0.8
            color: selected ? "#000" : "#AAA"
            Behavior on color { ColorAnimation { duration: 300 } }
            Behavior on scale { PropertyAnimation { duration: 300 } }
        }
    
        MouseArea {
            anchors.fill: delegate
            onClicked: {
                categories.currentIndex = index
                if(categories.currentUrl == url)
                    newsModel.reload()
                else
                    categories.currentUrl = url
            }
        }
    }
    
    

    Feeds.qml

    import QtQuick 2.3
    
    ListModel {
        ListElement { name: "Top Stories"; url: "http://feeds.bbci.co.uk/news/rss.xml" }
        ListElement { name: "World"; url: "http://feeds.bbci.co.uk/news/world/rss.xml" }
        ListElement { name: "UK"; url: "http://feeds.bbci.co.uk/news/uk/rss.xml" }
        ListElement { name: "Business"; url: "http://feeds.bbci.co.uk/news/business/rss.xml" }
        ListElement { name: "Politics"; url: "http://feeds.bbci.co.uk/news/politics/rss.xml" }
        ListElement { name: "Health"; url: "http://feeds.bbci.co.uk/news/health/rss.xml" }
        ListElement { name: "Education & Family"; url: "http://feeds.bbci.co.uk/news/education/rss.xml" }
        ListElement { name: "Science & Environment"; url: "http://feeds.bbci.co.uk/news/science_and_environment/rss.xml" }
        ListElement { name: "Technology"; url: "http://feeds.bbci.co.uk/news/technology/rss.xml" }
        ListElement { name: "Entertainment & Arts"; url: "http://feeds.bbci.co.uk/news/entertainment_and_arts/rss.xml" }
    }
    
    

    NewsDelegate.qml

    import QtQuick 2.3
    
    Column {
        id: news
        spacing: 8
    
        //used to seperate news item
        Item { height: news.spacing; width: news.width }
    
        Row {
            width: parent.width
            height: children.height
            spacing: news.spacing
    
            Image {
                id: titleImage
                source: thumbnail
            }
    
            Text {
                width: parent.width - titleImage.width
                wrapMode: Text.WordWrap
                font.pointSize: 20
                font.bold: true
                text: title
            }
        }
    
        Text {
            width: parent.width
            font.pointSize: 9
            font.italic: true
            text: pubDate + " (<a href=\"" + link + "\">Details</a>)"
            onLinkActivated: {
                Qt.openUrlExternally(link)
            }
        }
    
        Text {
            width: parent.width
            wrapMode: Text.WordWrap
            font.pointSize: 10.5
            horizontalAlignment: Qt.AlignLeft
            text: description
        }
    }
    
    

    Titlebar.qml

    import QtQuick 2.3
    
    Row {
        id: titlebar
        width: parent.width
        height: 22
        layoutDirection: Qt.RightToLeft
    
        property point mPos: Qt.point(0,0)
    
        Image {
            id: closebutton
            width: 22
            height: 22
            fillMode: Image.PreserveAspectFit
            source: "qrc:/close.png"
    
            MouseArea {
                anchors.fill: parent
                onClicked: {
                    Qt.quit()
                }
            }
        }
    
        Rectangle {
            width: titlebar.width - closebutton.width
            height: titlebar.height
            color: "#000"
    
            MouseArea {
                anchors.fill: parent
                onPressed: {
                    mPos = Qt.point(mouseX, mouseY)
                }
                onPositionChanged: {
                    mainWindow.setX(mainWindow.x + mouseX - mPos.x)
                    mainWindow.setY(mainWindow.y + mouseY - mPos.y)
                }
            }
        }
    }
    
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved