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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:01:10+00:00 2026-05-24T06:01:10+00:00

I wrote a char device driver and am now writing a QT wrapper which

  • 0

I wrote a char device driver and am now writing a QT “wrapper” which part of it is to get a signal to fire when the device becomes readable via the poll mechanism. I had tried to do:

QFile file("/dev/testDriver");
if(file.open(QFile::ReadOnly)) {
  QSocketNotifier sn(file.handle(), , QSocketNotifier::Read);
  sn.setEnabled(true);
  connect(&sn, SIGNAL(activated(int)), &this, SLOT(readyRead()));
}

But readyRead was never called and my driver never reported having its poll method called.

I was able to get the following code to work so I know my driver is working

QFile file("/dev/testDriver");
if(file.open(QFile::ReadOnly)) {
    struct pollfd fd;
    fd.fd = file.handle();
    fd.events = POLLIN;

    struct pollfd fds[] = {fd};
    int ready;
    qDebug() << "Started poll";
    ready = poll(fds, 1, -1);
    qDebug() << "Poll returned: " << ready;

    QTextStream in(&file);
    QTextStream out(stdout);
    out << in.readAll();
}

This properly waits for my driver to call wake_up and I can see two poll calls from my driver. One for the initial poll registration and one for when the wake_up happens.

Doing it this way I would probably have to spawn a separate thread which all it did was poll on this device and throw a signal and loop.

Is it possible to use QSocketNotifier in this way? The documentation of QFile::handle() seems to indicate it should be.

  • 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-24T06:01:11+00:00Added an answer on May 24, 2026 at 6:01 am

    Your QSocketNotifer gets destroyed as soon as that if block ends. It doesn’t stand a chance of reporting anything.

    You must keep that socket notifier alive as long as you want that file to be monitored. The simplest way of doing that is probably keeping a QSocketNotifer* member in one of your classes.

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

Sidebar

Related Questions

I wrote kernel module which do nf_register_hook and use character device mechanism to get
I have to write a linux char device, which handles ioctl (without BKL) functions
i'm writing a char device in linux - xubuntu , and i'm wondering if
I write a linux char device driver to simulate a file. The data is
I wrote a managed C++ class that has the following function: void EndPointsMappingWrapper::GetLastError(char* strErrorMessage)
Below is my current char* to hex string function. I wrote it as an
i have an char array b[20] which i want to write into a file
I'am writing a HTTP proxy that is part of a test/verification system. The proxy
I wrote a function that searches for a char in an array, and if
I wrote following program int main () { char a=0xf; a=a+1; printf(%c\n,a); } the

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.