Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qt 4.8.4 - Problem generating click - coordinates used by QPoint
Forum Updated to NodeBB v4.3 + New Features

Qt 4.8.4 - Problem generating click - coordinates used by QPoint

Scheduled Pinned Locked Moved Mobile and Embedded
1 Posts 1 Posters 665 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    portegael
    wrote on last edited by
    #1

    Hello guys,

    I am working on an embedded linux project using Qt 4.8.4 and I want to generate click to a given position.

    First I will give you a sum-up of my code and then explains the problem.

    main.cpp : Declare a new QApplication

    @int main( int argc, char *argv[] )
    {
    main_app = new QApplication( argc, argv ) ;

    [....]

    }@

    mainwindow.h : header of the mainwindow

    @class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public :

    void generate_click( int coord_x, int coord_y ) ;

    [...]
    }@

    mainwindow.cpp: definition of my function

    @void MainWindow::generate_click(int x, int y)
    {

    printf("Enter generate_click : (%d/%d)\n", x, y) ;

    QPoint _pos_click( x, y ) ;
    QWidget *receiver = QApplication::widgetAt( _pos_click ) ;

    if(receiver == 0)
    printf("No element at the position (%d, %d)\n", x, y) ;
    else
    {
    QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonPress, receiver->mapFromGlobal(_pos_click), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
    main_app->postEvent(receiver, event);
    QMouseEvent *release = new QMouseEvent(QEvent::MouseButtonRelease, receiver->mapFromGlobal(_pos_click), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
    main_app->postEvent(receiver, release);
    }
    }@

    This way it is NOT working, even if the coordinates are good in my first printf. I never see the error "receiver == 0 ). If we modify the Qt library to add a log in the function PostEvent we see that x or y (randomly) equal 0 or 1 so that's why there is no click.

    If I modify x and y this way (give a value to x / y ) it WORKS all the time :

    @void MainWindow::generate_click(int x, int y)
    {

    x = 20 ;
    y = 80 ;

    printf("Enter generate_click : (%d/%d)\n", x, y) ;

    QPoint _pos_click( x, y ) ;
    QWidget *receiver = QApplication::widgetAt( _pos_click ) ;

    if(receiver == 0)
    printf("No element at the position (%d, %d)\n", x, y) ;
    else
    {
    QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonPress, receiver->mapFromGlobal(_pos_click), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
    main_app->postEvent(receiver, event);
    QMouseEvent *release = new QMouseEvent(QEvent::MouseButtonRelease, receiver->mapFromGlobal(_pos_click), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
    main_app->postEvent(receiver, release);
    }
    }@

    If I add an addition to the coordinate I receive, it also WORKS !

    @void MainWindow::generate_click(int x, int y)
    {

    x = x + 5;
    y = y + 5;

    printf("Enter generate_click : (%d/%d)\n", x, y) ;

    QPoint _pos_click( x, y ) ;
    QWidget *receiver = QApplication::widgetAt( _pos_click ) ;

    if(receiver == 0)
    printf("No element at the position (%d, %d)\n", x, y) ;
    else
    {
    QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonPress, receiver->mapFromGlobal(_pos_click), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
    main_app->postEvent(receiver, event);
    QMouseEvent *release = new QMouseEvent(QEvent::MouseButtonRelease, receiver->mapFromGlobal(_pos_click), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
    main_app->postEvent(receiver, release);
    }
    }@

    Even if the Qt documentation says that QPoint is expecting an integer, I think that the addition or the fact that we give fixed coordinates will cast them in a type expected by QPoint.

    Are you able to tell me why the first example is not working ?

    I hope my problem is clear and let me know if you need more information.
    Thanks in advance.

    Gaël

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved