PDA

View Full Version : [SOLVED] Qt: Move cursor via console application



hakermania
March 9th, 2011, 12:48 PM
This is the code but the program unexpectedly finishes at the line taht say s setPos(x,y) (segmentation fault). What do I do wrong?

#include <QtGui>
#include <QtCore> //for any occasion, a lot of includes...
#include <QApplication>
int main()
{
QCursor *cur = new QCursor;
cur->setPos(0 ,0); //HERE it crashes
return 0;
}

The project file is:

QT -= gui

TARGET = curmove
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app


SOURCES += main.cpp

GeneralZod
March 9th, 2011, 01:08 PM
From the docs (http://doc.qt.nokia.com/latest/qcursor.html):



Attempting to use a QCursor that was created before QApplication will result in a crash.

hakermania
March 11th, 2011, 09:27 PM
So, how exactly should the code be???

hakermania
March 27th, 2011, 12:53 AM
that's it:

#include <QtGui/QCursor>
#include <QApplication>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QCursor *cur = new QCursor;
cur->setPos(0,0);
return 0;

return a.exec();
}