Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7162805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:47:45+00:00 2026-05-28T13:47:45+00:00

I need to display a string on a simulation screen. For that I’m supposed

  • 0

I need to display a string on a simulation screen. For that I’m supposed to read the text from an existing Filename.txt/Filename.csv file. The text parameter is updated as shown in the below piece of code. I need to access the string from a text file and use it in MarqueeText element. The Accessed string shall be used in the text field of the MarqueeText element.

MarqueeText {
     id:scrolltext
     width: 255
     height: 48
     anchors.verticalCenter: parent.horizontalCenter
     text:   //i need to access the string in text file to be displayed
}

Please help me with this. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:47:45+00:00Added an answer on May 28, 2026 at 1:47 pm

    Follow the wiki page to read about accessing files in QML. Nokia Wiki Forum http://web.archive.org/web/20150227025348/http://developer.nokia.com/community/wiki/Reading_and_writing_files_in_QML

    Summary:

    Create a custom QML type, FileIO:

    fileio.h

    #ifndef FILEIO_H
    #define FILEIO_H
    
    #include <QObject>
    
    class FileIO : public QObject
    {
        Q_OBJECT
    
    public:
        Q_PROPERTY(QString source
                   READ source
                   WRITE setSource
                   NOTIFY sourceChanged)
        explicit FileIO(QObject *parent = 0);
    
        Q_INVOKABLE QString read();
        Q_INVOKABLE bool write(const QString& data);
    
        QString source() { return mSource; };
    
    public slots:
        void setSource(const QString& source) { mSource = source; };
    
    signals:
        void sourceChanged(const QString& source);
        void error(const QString& msg);
    
    private:
        QString mSource;
    };
    
    #endif // FILEIO_H
    

    fileio.cpp

    #include "fileio.h"
    #include <QFile>
    #include <QTextStream>
    
    FileIO::FileIO(QObject *parent) :
        QObject(parent)
    {
    
    }
    
    QString FileIO::read()
    {
        if (mSource.isEmpty()){
            emit error("source is empty");
            return QString();
        }
    
        QFile file(mSource);
        QString fileContent;
        if ( file.open(QIODevice::ReadOnly) ) {
            QString line;
            QTextStream t( &file );
            do {
                line = t.readLine();
                fileContent += line;
             } while (!line.isNull());
    
            file.close();
        } else {
            emit error("Unable to open the file");
            return QString();
        }
        return fileContent;
    }
    
    bool FileIO::write(const QString& data)
    {
        if (mSource.isEmpty())
            return false;
    
        QFile file(mSource);
        if (!file.open(QFile::WriteOnly | QFile::Truncate))
            return false;
    
        QTextStream out(&file);
        out << data;
    
        file.close();
    
        return true;
    }
    

    Register the new QML type:

    #include "fileio.h"
    
    Q_DECL_EXPORT int main(int argc, char *argv[])
    {
       ...
        qmlRegisterType<FileIO, 1>("FileIO", 1, 0, "FileIO");
        ...
    }
    

    Actual QML Usage:

    import QtQuick 1.1
    import FileIO 1.0
    
    Rectangle {
        width: 360
        height: 360
        Text {
            id: myText
            text: "Hello World"
            anchors.centerIn: parent
        }
    
        FileIO {
            id: myFile
            source: "my_file.txt"
            onError: console.log(msg)
        }
    
        Component.onCompleted: {
            console.log( "WRITE"+ myFile.write("TEST"));
            myText.text =  myFile.read();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in a GridView column i need to display a string composed from a set
I am writing a month calendar-style control, and need to display a string that
I need to display a string which has a white space on a asp.net
I need to format a decimal value into a string where I always display
I need to display a variable-length message and allow the text to be selectable.
I need to display the log entries from a database. Of course the log
I need to display text in an iPhone application, something like the way a
I have a time in millis and I need to display that to the
i have the next list: SortedList<Decimal, KeyValuePair<string,string>> datos; And i need display this in
HI, I am in a situation that I need to display notification when call

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.