Is there a way to add a mouse event to a thread?
I tried the following after defining Clicked as a QMouseEvent in the header file:
[
Clicked = new QMouseEvent(this);
connect(Clicked, SIGNAL(mousePressEvent()), this, SLOT(MouseClicked()));
timer->moveToThread(&MouseThread);
MouseThread.start();
]
I defined mousePressEvent() n the header under signals and MouseClicked() under slots. I also wrote the MouseClicked as a void function:
[
void Game::MouseClicked()
{
lbl->setText("Works");
}
]
A label was defined to give me feedback if the thread worked.
But I get errors when implementing this as it would seem as if you can't use QMouseEvent in connect
Re: Is there a way to add a mouse event to a thread?
There are so many things wrong here, it's hard to know where to start.
First, mousePressEvent() is not a signal, it is a protected virtual member function of QWidget that is called whenever the user presses a mouse button while inside the widget. If you derive from (or use a class derived from) QWidget, you will likely override the QWidget implementation with your own method if you need to handle this event in a custom way.
Second, the QMouseEvent class inherits from the QEvent base class, which -does not- inherit from QObject, so it can't emit signals in the first place. So defining a "Clicked" instance of QMouseEvent and trying to connect to a non-existent "mousePressEvent" signal of the QMouseEvent class will never work.
Third, I don't think you understand the basics of how signals and slots work.
Fourth, I have no idea what you are trying to do with a timer and whatever MouseThread is, or why you think you even need a thread to handle mouse clicks in your game.
Why don't you start by reading the Qt Signals and Slots tutorial, then move on to the Threading Basics tutorial, and read Maya Posch's excellent blog post for dessert.