Results 1 to 7 of 7

Thread: event or thread

  1. #1
    Join Date
    Sep 2008
    Posts
    22
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default event or thread

    hy,

    I have a keypad in dev/input/event0
    I can read in the value like that :

    main :

    if ((fd = open( "dev/input/event0", O_RDONLY)) < 0) {
    perror("evtest");
    exit(1);
    }
    while (1)
    {
    rd = read(fd, ev, sizeof(struct input_event) * 64);
    }

    i want to use this value in an qt application but i can't put this in the main of my qtapp because the wile(1) stop the application and i can't do app->exec();

    how can i do?
    - use a thread : one to read my keypad and the other can do app->exec() to start my Qt application.
    - or there is a mean to use the input event of linux like some event in a qt window but i don't know how i can that.

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: event or thread


  3. #3
    Join Date
    Sep 2008
    Posts
    60
    Thanks
    8
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: event or thread

    EDIT: sorry, I did not see Caduel's post above: he is right, please disregard what is said below

    I'm afraid using a thread is the only option.

    In order to use events you need to open QFile on a device and connect its readyRead() signal to a custom slot. But the problem is QFile does not emit signals:

    Unlike other QIODevice implementations, such as QTcpSocket, QFile does not emit the aboutToClose(), bytesWritten(), or readyRead() signals. This implementation detail means that QFile is not suitable for reading and writing certain types of files, such as device files on Unix platforms.
    And I do not see any other suitable subclasses of QIODevice that would allow opening devices.
    Last edited by yuriry; 2nd October 2008 at 19:02.

  4. #4
    Join Date
    Sep 2008
    Posts
    22
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: event or thread

    thanks for the response.

    I have spent my afternoon in it and the socket looks an importante notion but i haven't yet understood how use it.

    just to be sure : i can't connect a thread just like that ?
    int main()
    {
    MyThread a;
    MyThread b;
    a.start();
    b.start();
    QObject::connect(a, SIGNAL(thekey()), b, SLOT(recep()));

    error:
    tread.cpp: In function «int main()»:
    tread.cpp:44: erreur: incomplete type «QObject» used in nested name specifier
    tread.cpp:45: erreur: incomplete type «QObject» used in nested name specifier

    that would be very easy.

    i will try the socket thank you for your help

  5. #5
    Join Date
    Sep 2008
    Posts
    60
    Thanks
    8
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: event or thread

    Take a look at the attached example where I used Caduel's advice (QSocketNotifier). It works with /dev/input/mouse1 on my laptop and is specific to mouse events (size of event is 3 bytes). But it'll give you a starting point on how to use signals and slots without using threads.

    I run it like this: sudo ./device /dev/input/mouse1
    Attached Files Attached Files

  6. #6
    Join Date
    Sep 2008
    Posts
    22
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: event or thread

    it's magic, i think it is exactly what i want.
    i will put it for qt3.

    thank you very much

  7. #7
    Join Date
    Sep 2008
    Posts
    22
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: event or thread

    it's ok that running I love the sockets now

Similar Threads

  1. Qt event queue overloading?
    By gct in forum Qt Programming
    Replies: 3
    Last Post: 17th March 2008, 18:39
  2. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  3. Main Thread Event loop
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2007, 12:10
  4. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 00:49
  5. Workload in a QThread blocks main application's event loop ?
    By 0xBulbizarre in forum Qt Programming
    Replies: 14
    Last Post: 9th April 2006, 21:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.