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 3315416
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:20:52+00:00 2026-05-17T22:20:52+00:00

How do I read a FIFO/named pipe line by line from a C++/Qt Linux

  • 0

How do I read a FIFO/named pipe line by line from a C++/Qt Linux app?

Today I can open and read from a fifo from a Qt program,
but I can’t get the program to read the data line by line.
Qt reads the entire file, meaning he waits until the “sender” closes his session.

Let’s take a example with some shell commands to show what I would like the app to do.

First create a fifo

mkfifo MyPipe

Then we can use cat to read from the fifo

cat MyPipe 

And then we send some data in with another cat

cat > MyPipe

And then start to type something, and every time you hit enter it arrives at the reader.
And then when you close it with Ctrl+D both sides end.

Now the sender is easy to create with a QTextStream,
you just need to flush when you want to send.

QFile file("MyPipe");
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
    return;

QTextStream out(&file);
for(int i=0; i<3; i++) {
    out << "Hello...: " << i << "\n";
    out.flush();
    sleep(2);
}

file.close();

But then to write a little reader that read line by line is where I’m stuck right now,
all my tries with the Qt lib ends up with that I get the data but
not until the sender uses file.close() on the fifo.
Not when he flush, as occurs when I use cat to read.

Like this example:

QFile file("MyPipe");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
    return 0;

QTextStream in(&file);
QString line;
do {
    line = in.readLine();
    qDebug() << line;
} while (!in.atEnd());


file.close();

What am I missing?

It just feels like I need to use some kind of isReady or lineAvailable on
the stream or something like that,
but I can’t find anything in the docs that fits…

/Thanks


Note:

If I go with the low level c style and read one char at the time I do
get the style Im searching for.
But it would be nice to be able to do the same Qt style.

FILE *fp;
fp=fopen("MyPipe", "r");
char c;
while((c=getc(fp)) != EOF)
{
    printf("%c",c);
}
fclose(fp);

Update:

When I start a debugger the program is hanging on the readLine(),
and do not continue until the other party closes the fifo.

And I do get the same using “>>”

    line = in.readLine();
    in >> line;
  • 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-17T22:20:52+00:00Added an answer on May 17, 2026 at 10:20 pm

    Use the low level c style and read one char at the time.

    FILE *fp;
    fp=fopen("MyPipe", "r");
    char c;
    while((c=getc(fp)) != EOF)
    {
        printf("%c",c);
    }
    fclose(fp);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Read about the z-index issue and tried anything, but just can't seem to fix
I read this PHP RegEx page , but either I'm missing something, misreading something,
I read an interesting DailyWTF post today, Out of All The Possible Answers... and
I read some post about ASP.NET MVC application, but I found only article on
I read about Change the delegate of MGTwitterEngine and don't really get it. I
I read the following statement: ArrayLists are unsynchronized and therefore faster than Vector, but
Having read the threads Is SqlCommand.Dispose enough? and Closing and Disposing a WCF Service
I read somewhere once that the modulus operator is inefficient on small embedded devices
I read the Git manual, FAQ, Git - SVN crash course, etc. and they
Please read the whole question. I'm not looking for an approach to managing multi-lingual

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.