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

  • SEARCH
  • Home
  • 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 6952343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:20:12+00:00 2026-05-27T14:20:12+00:00

I’m using Qt and QProcess to read some data from other tools and printing

  • 0

I’m using Qt and QProcess to read some data from other tools and printing them on my app. Think of it being a “terminal”, for example.

I’m processing data using QProcess::canReadLine() and QProcess:readLine(), and that’s wonderful. But some tools use \r to print progress bars on screen, and that’s screwing with my parser. Since there is never some line to be read, my app just wait until the process finishes to print the last line: many lines glued together with \r instead of \n.

Anyways, is there someway to tell QProcess to use \r as linebreak also? I thought of implementing my QIODevice subclass, but I’d need to reimplement QProcess too, so that seems to be not the optimal approach.

I thought of using a middle buffer, and use this buffer to signal “hasLine” to my main program. I’d use QProcess::readyRead to populate the buffer, and then the buffer to populate my main app, but I’d like to just tell Qt that a \r is also OK as a linebreak. Is that possible?

  • 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-27T14:20:13+00:00Added an answer on May 27, 2026 at 2:20 pm

    I don’t think it’s possible to directly tell Qt to use ‘\r’ as a linebreak. I thought that QTextStream could do that, but looking at its sources right now it seems to me that I was wrong.

    One funny way of doing it would be to implement a custom QIODevice subclass that reads from another QIODevice and just replaces all ‘\r’s with ‘\n’s, delegating all other methods excep read() varieties to the original device. Then readLine() and QTextStream would work on the resulting stream just fine, I think. You’d have to deal somehow with the possible ‘\r\n’ sequence, though. The upside is that you don’t have to do any buffering in that class.

    Something along these lines:

    class CRFilter: public QIODevice {
        Q_OBJECT
    public:
        CRFilter(QIODevice *device);
    protected:
        virtual qint64 readData(char *data, qint64 maxSize);
        virtual qint64 writeData(const char *data, qint64 maxSize);
    private:
        QIODevice *device;
    };
    
    CRFilter::CRFilter(QIODevice *device):
    device(device)
    {
        // delegate the readyRead() signal to this object
        connect(device, SIGNAL(readyRead()), SIGNAL(readyRead()));
        // and maybe other signals like bytesWritten() too...
    }
    
    qint64 CRFilter::readData(char *data, qint64 maxSize)
    {
        qint64 res = device->read(data, maxSize);
        for (qint64 i = 0; i < res; i++) {
            if (data[i] == '\r')
                data[i] = '\n';
        }
        return res;
    }
    
    qint64 CRFilter::writeData(const char *data, qint64 maxSize)
    {
        return device->write(data, maxSize);
    }
    

    Then you just do this:

    QProcess process; // use QProcess methods on this
    CRFilter reader(&p); // use QIODevice methods on this
    reader.open(QIODevice::ReadWrite); // need this to convince read()/write() methods to work
    

    I hadn’t actually tested it, so it probably needs some debugging to get it right. I also think it’s a bit ugly, but can’t think of any really elegant solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from

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.