Results 1 to 5 of 5

Thread: How does QT know?

  1. #1
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default How does QT know?

    Hi I'm trying to implement the idea of signals and slots outside of Qt and I was wondering about how Qt actually knows which button and hence which object you click on in a user interface? Does it use some sort of inbuilt container whenever you create clickable buttons in the Ui and then it iterates through that container to determine which button has been pressed?

    Since this is an openGl implementation that I'm creating the interface in, the easiest way that I can think of is to have members inside the button class that store the dimensions and positions of the buttons and chuck all the buttons into a qlist/container and then whenever a mouse click even occurs, iterate through the list to determine if the click occurred over the buttons. However this seems like a really slow way of going about things and performance is important for my purpose and I was wondering how else I might go about solving this problem?

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: How does QT know?

    Nobody seems to know. (Of course, Qt source code is available, so somebody should be able to find out)

    I guess that iterating through a list of button coordinates is in fact really fast -- compared to and considering the speed of a human being clicking a mouse. Going through a list of a handfull (or many handfulls) of things and doing comparisons of integer values is something that will never be a bottleneck.

    What I think Qt in general needs to do is more complicated by many magnitutes.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How does QT know?

    Exactly how Qt does it for widget-based UIs in is the Qt code. For very busy scenes a binary space partitioning algorithm, as used in QGraphicsScene, is worth the effort. Another approach that is commonly used is the R-Tree. For the average widget UI of a few dozen visible widgets I doubt the complexity is warranted.

  4. #4
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How does QT know?

    Thanks guys, much appreciated... I'll look into your suggestions. But by the sounds of it, 40 buttons or so won't be too much of a problem so a simple method may indeed be the best solution.

  5. #5
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Thanks
    29
    Thanked 50 Times in 47 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How does QT know?

    what the signals and slots is the communication between two different objects. So, there is no problem in how qt knows that they are communicating, as we are actually giving the permission to the object to emit the signal and to slot for accepting it.

    A signal is a method that is emitted rather than executed when called. So from your viewpoint as a programmer, you declare prototypes of signals that might be emitted. Do not
    implement signals; just declare them in the class declaration in the signals section of your class.
    A slot is a member function that can be invoked as a result of signal emission. You have to tell the compiler which methods to treat as slots by putting them in one of these sectionsublic slots, protected slots, or private slots. The protection level protects the slot only when it is being used as a method. You can still connect a private slot or a protected slot to a signal that you receive from another class. When it comes to connecting signals and slots, you can connect any number of signals to
    any number of slots. This means that a single slot can be connected to many signals, and a single signal can be connected to many slots. There are no limitations to how you interconnect your objects. When a signal is emitted, all slots connected to it are called. The order of the calls is undefined, but they do get called.

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.