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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:54:13+00:00 2026-06-13T12:54:13+00:00

I am developing for a touch screen and need to detect touch events to

  • 0

I am developing for a touch screen and need to detect touch events to turn the screen back on. I am using Qt and sockets and have run into an interesting issue.

Whenever my QSocketNotifier detects the event it sends me infinite notices about it. Therefore I need to close and open the event file to cycle the notifier (inputNotifier in the below code). The problem usually arises several minutes after the device has been running and the file (inputDevice) suddenly changes it’s handle from 24 to something else (usually 17).

I am not sure what to do, because the initial connect statement is linked to the initial Notifier pointer. If I create a new Notifier using the new handle, the connect is invalid. As far as I can tell there is no option to set a new socket value on a running QSocketNotifier. Suggestions? The relevant code is below:

#include "backlightcontroller.h"
#include <QTimer>
#include <QFile>
#include <syslog.h>
#include <QDebug>
#include <QSocketNotifier>




BacklightController::BacklightController(QObject *parent) :
    QObject(parent)
{
    backlightActive = true;

    // setup timer
    trigger = new QTimer;
    trigger->setSingleShot(false);
    connect(trigger, SIGNAL(timeout()), SLOT(deactivateBacklight()));

    idleTimer = new QTimer;
    idleTimer->setInterval(IDLE_TIME * 1000);
    idleTimer->setSingleShot(false);
    connect(idleTimer, SIGNAL(timeout()), SIGNAL(idled()));
    idleTimer->start();

    // setup socket notifier
    inputDevice = new QFile(USERINPUT_DEVICE);
    if (!inputDevice->open(QIODevice::ReadOnly))
    {
        syslog (LOG_ERR, "Input file for Backlight controller could not been opened.");
    }
    else
    {
        inputNotifier = new QSocketNotifier(inputDevice->handle(), QSocketNotifier::Read);
        inputNotifier->setEnabled(true);
        connect(inputNotifier, SIGNAL(activated(int)), SLOT(activateBacklight()));
    }

    qDebug()<<"backlight socket: "<<inputNotifier->socket();

    // read out settings-file
    QString intensity = Global::system_settings->getValue("BelatronUS_backlight_intensity");
    if (intensity.length() == 0) intensity = "100";
    QString duration = Global::system_settings->getValue("BelatronUS_backlight_duration");
    if (duration.length() == 0) duration = "180";
    QString always_on = Global::system_settings->getValue("BelatronUS_backlight_always_on");
    if (always_on.length() == 0) always_on = "0";

    setIntensity(intensity.toInt());
    setDuration(duration.toInt());

    if (always_on == "0")
      setAlwaysOn(false);
    else
      setAlwaysOn(true);
}


BacklightController::~BacklightController()
{
    trigger->stop();
    inputNotifier->setEnabled(false);
    inputDevice->close();

    delete trigger;
    delete inputDevice;
    delete inputNotifier;
}


void BacklightController::setCurrentIntensity(int intensity)
{
    // adapt backlight intensity
    QFile backlightFile("/sys/class/backlight/atmel-pwm-bl/brightness");
    if (!backlightFile.open(QIODevice::WriteOnly))
    {
      syslog (LOG_ERR, "Backlight intensity file could not been opened.");
    }
    else
    {
      QString intensityString = QString::number(TO_BRIGHTNESS(intensity));
      if (backlightFile.write(
              qPrintable(intensityString), intensityString.length()
              ) < intensityString.length())
      {
        syslog (LOG_ERR, "Backlight intensity could not been changed.");
      }
      backlightFile.close();
    }
}


void BacklightController::resetNotifier()
{

    inputDevice->close();
    if (!inputDevice->open(QIODevice::ReadOnly))
    {
        syslog (LOG_ERR, "BacklightController::%s: Input file could not been opened.", __FUNCTION__);
    }
    qDebug()<<"reset, handle: "<<inputDevice->handle();
    //inputNotifier=QSocketNotifier(inputDevice->handle(), QSocketNotifier::Read);


    // restart timer after user input
    idleTimer->start();
}


void BacklightController::activateBacklight()
{
    // only activate backlight, if it's off (avoid to useless fileaccess)
    if (!backlightActive)
    {
        setCurrentIntensity(_intensity);
        backlightActive = true;
        emit backlightActivated();
    }

    // restart backlight timeout, but only if we don't want the backlight to shine all the time
    if (!_alwaysOn)
        trigger->start();

    // reset notifier to be able to catch the next userinput
    resetNotifier();
}


void BacklightController::deactivateBacklight()
{
    // don't turn it off, if it's forced on
    if (!_alwaysOn)
    {
        if (backlightActive)
        {
            // only deactivate backlight, if it's on (avoid to useless fileaccess)
            setCurrentIntensity(BACKLIGHT_INTENSITY_OFF);
            backlightActive = false;
            emit backlightDeactivated();
        }
    }
    qDebug()<<"trigger stopping";
    trigger->stop();
}


void BacklightController::setIntensity(int intensity)
{
    if (intensity > 100)
        intensity = 100;
    else if (intensity < 0)
        intensity = 0;

    _intensity = intensity;

    // write new intensity to file if it's active at the moment
    if (backlightActive)
    {
        setCurrentIntensity(_intensity);
        trigger->start();
    }
}


void BacklightController::setDuration(int duration)
{
    if (duration < 1)
        duration = 1;

    _duration = duration;
    trigger->setInterval(_duration * MS_IN_SEC);

    // reset trigger after changing duration
    if (backlightActive)
    {
        trigger->start();
    }
}


void BacklightController::setAlwaysOn(bool always_on)
{
    _alwaysOn = always_on;

    // tell the timer what to to now
    if (_alwaysOn)
    {
        this->activateBacklight();
        trigger->stop();
    }
    else
    {
        trigger->start();
    }
}
  • 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-06-13T12:54:14+00:00Added an answer on June 13, 2026 at 12:54 pm

    I seem to have found a working solution for now. It’s not the greatest so if there are better solutions I would be interested to hear them. The reason I did not think of this before is because I thought if I had a new connect statement in a function it would have limited scope as the function ended.

    The solution was to simply check for an occurrence of the handle change in the file and then create a new pointer for the notifier using that handle. Then re-enable the notifier because it has likely been disabled by now and then create a new connect statement for the pointer. This is the code I used, added just below the closing and reopening of the event file:

    if(inputDevice->handle()!=inputNotifier->socket()){
        inputNotifier = new QSocketNotifier(inputDevice->handle(), QSocketNotifier::Read);
        inputNotifier->setEnabled(true);
        connect(inputNotifier, SIGNAL(activated(int)), SLOT(activateBacklight()));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an Android application and I need to handle various touch events.
I'm currently developing a touch screen application using C# (.NET 4.0) and WPF for
I am developing my first game with cocos2d and i have run into a
I'm developing an app which requires the system to get the touch events even
I have iPod touch 4th. And I'm developing iPhone app with it. I use
I'm developing my own OS, but for this I need to touch on linking,
Developing a project of mine I realize I have a need for some level
I am developing a web browser for a touch-screen kiosk and the scrollbars on
I'm developing an application on 9900 where both Trackball and touch screen are available.
I am developing an app using Sencha Touch 1.1.1. I would like to create

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.