Mouse click event in qt 3.0.3 - qt

Mouse button clicki am trying to create an automatic mouse click event at a particular co ordinate.
This source code moves the mouse pointer to the co ordinate region but it is not clicking.
please help me to solve this problem or suggest any new idea to automate mouse click event.
Note: i am using QT 3.0.3
void mMouseClickFunction()
{
QWidget *d = QApplication::desktop()->screen();
int w=d->width(); // returns desktop width
int h=d->height();
printf("w=%d\nh=%d\n",w,h);
int x,y;
printf("Enter the points...\n");
scanf("%d%d",&x,&y);
QApplication::desktop()->cursor().setPos(x,y);
QPoint pt(x,y);
std::cout << pt.x() << " " << pt.y() << std::endl;
QMouseEvent *e = new QMouseEvent(QEvent::MouseButtonPress, pt,Qt::LeftButton, 0);
QApplication::sendEvent(d, e);
std::cout << "in contentsMousePressEvent"<< e->x() << " " << e->y() << std::endl;
QMouseEvent *p = new QMouseEvent(QEvent::MouseButtonRelease, pt,Qt::LeftButton, 0);
QApplication::sendEvent(d, p);
std::cout << "in contentsMouseReleaseEvent"<< p->x() << " " << p->y() << std::endl;
}

QApplication::sendEvent sends an event internal to the QApplication, not a system wide event. You probably need to be system specific to send out an event like that. Here is the function call for windows:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310(v=vs.85).aspx
But even with that kind of call, you will be limited to certain windows, unless you have UIAccess to be true, and your program is a signed application located in the right part of the harddrive.
EDIT: Here is a page that has some examples for sending input in Linux:
http://www.linuxquestions.org/questions/programming-9/simulating-a-mouse-click-594576/
Hope that helps.

Related

Unexplained time offset in QApplication event loop

I'm currently working with a program for predicting the locations of satellites in real-time. Something similar to this. The underlying library uses system time as input.
time_t now(time(0));
This program accurately predicts the real-time position of satellites when I run it on a C++ console application using Qt Creator.
The problem is when I use it in a fully-fledged Qt Gui application with a QApplication object in the main function. In the program, the prediction function is periodically by the timer event function. That way I update the positions every 2 seconds. Unfortunately, The output doesn't match (either on the GUI or when I print it). It is like the orbital propagator is using a different time when calculating the satellite positions.
void TrackingManager::timerEvent(QTimerEvent *event)
{
int nNumSats = m_Satellites.size() ;
//std::cout << __func__ << " - Number of satellites = " << nNumSats << std::endl;
std::vector<SatPosition> vSatPositions;
if (nNumSats >= 0)
{
time_t now(time(0));
std::cout << __func__ << "time(0) = " << asctime(gmtime(&now)) << std::endl;
for(int i = 0; i < nNumSats; i++)
{
// Get satellite names and calculate position, altitude etc
SatPosition spPos;
GetInstantPredict(m_Satellites[i], now, spPos);
vSatPositions.push_back(spPos);
}
emit UpdateSatPosition(vSatPositions);
}
}
Even more confusing, the program works fine when I run the debugger (GDB on Ubuntu). It is as if GDB somehow manages to "fix" the problem. Does this make any sense?

NPP function returns nppiFilterRow_8u_C1R CUDA KERNEL execution error

I am using nvidia nsight application to rotate and blur images. I am using the NPP libraries for the same,
The oDeviceDst gets filled the data from the output of function rotate, which is working fine.The code is shown below: Also note that the below piece of code is in a for loop for some rotation angles.
npp::ImageNPP_8u_C1 oDeviceDst(768 , 768);
Npp32s masksize = (Npp32s)KERNEL_LENGTH;
Npp32s anchor = (Npp32s)KERNEL_RADIUS;
NppiSize SzROI ={(int)oDeviceDst_gauss.width(),(int)oDeviceDst_gauss.height()};
std::cout << " anchor " << anchor << std::endl; std::cout << " masksize " << masksize << std::endl;
NppStatus status2 = nppiFilterRow_8u_C1R(oDeviceDst.data(), oDeviceDst.pitch(), oDeviceDst_gauss.data(), oDeviceDst_gauss.pitch(), SzROI, (Npp32s*)h_Kernel, masksize , anchor, int(sumh));
std::cerr << "status of blur is" << status2 << std::endl;
But as soon as i run it(remote on target), I get a status of -1000.
status of blur is -1000.
logout
Has anyone faced a similar issue in usage of NPP libraries.

How to get camera intrinsics and extrinsics in openni2?

I have a primesense carmine 1.08 and carmine 1.09. I need the intrinsic parameters for the RGB and the IR camera and the extrinsics between the two. I use pcl with openni2 support. So I need to know the sensor parameters used by openni2/pcl.
Is there a way in openni2 to find the intrinsics and the extrinsics using openni2/pcl? Libfreenect2 has option to get IR and color camera intrinsics, but are these parameters same as that in openni? Are all these parameters extracated from sensor during runtime?
I tried to get it via pcl, but i get nan for the focal length and the principal points
int main (int argc, char** argv)
{
std::string device_id ("");
pcl::io::OpenNI2Grabber::Mode depth_mode =
pcl::io::OpenNI2Grabber::OpenNI_Default_Mode;
pcl::io::OpenNI2Grabber::Mode image_mode =
pcl::io::OpenNI2Grabber::OpenNI_Default_Mode;
pcl::io::OpenNI2Grabber grabber (device_id, depth_mode, image_mode);
grabber.start();
double fx,fy,px,py;
grabber.getDepthCameraIntrinsics(fx,fy,px,py);
cout << "fx=" << fx << endl;
cout << "fy=" << fy << endl;
cout << "px=" << px << endl;
cout << "py=" << px << endl;
return (0);
}
A similar question has been asked here https://stackoverflow.com/questions/41110791/openni-intrinsic-and-extrinsic-calibration. However it hasnt recieved any answers.

Qt : How to create a video from multiple QImages

How to create a .mp4 video out of multiple QImages in a Qt application.
Looking at QMediaRecorder examples, it only knows how to grab frames from camera. There seems to be no way to pass multiple QImages or some other image data type into QMediaRecorder simply to make a video out of them which has nothing to do with the camera.
Development Environment:
Using Qt 5.9.1 commercial version with app working on Android, iOS & OSX.
It is hard to ascertain exactly what you need to do here, considering it is not clear just how many images you are processing.
That being said, this is possible if you use a tool such as ffmpeg to generate the video, however it will require you to at the very least, write those images to disc.
Here is a working example I use to generate slideshows videos for youtube. The concatenation of images is ascertained by their naming scheme as saved on the drive.
sl << "-i" << md.sku(true) + "##%03d.png"; // Images input,
as such,
mysku##001.png // First Slide
mysku##002.png // Second Slide
mysku##003.png // Third Slide
mysku##004.png // Fourth Slide
VideoConvert::VideoConvert(Metadata &md, QFile &oggFile, QObject *parent) : QObject(parent)
{
QStringList sl;
tt.warning(md.duration());
tt.warning(md.length());
QString framerate = md.duration(true);
int hour = QString(md.length()).split(":").at(0).toInt();
int minute = QString(md.length()).split(":").at(1).toInt();
int second = QString(md.length()).split(":").at(2).toInt();
framerate.remove(".");
framerate.remove(QRegularExpression("^[0]*"));
sl << "-y"; // overwrite
sl << "-framerate" << QString::number(md.images().length())
+ "/" + QString::number(((hour * 60) * 60) + (minute * 60) + second);
sl << "-i" << md.sku(true) + "##%03d.png"; // Images input,
sl << "-i" << oggFile.fileName();
sl << "-c" << "copy";
sl << "/home/akiva/FrogCast/" + md.title(true) + " ⟪Wiki🔊Book⟫.mp4";
md.setName(sl.last());
QEventLoop convertEvent;
m_Convert.setReadChannelMode(QProcess::MergedChannels);
connect(&m_Convert, SIGNAL(readyRead()), this, SLOT(convert()));
connect(this, SIGNAL(converted()), &convertEvent, SLOT(quit()));
tt.process("Converting Video File");
for (int i=0; i < sl.length(); i++) {
QTextStream(stdout) << "\t" << sl.at(i) << endl;
}
if (QFile("/home/akiva/FrogCast/Cereproc/ffmpeg").exists()) {
m_Convert.start("/home/akiva/FrogCast/Cereproc/ffmpeg", sl);
} else {
m_Convert.start("ffmpeg", sl);
}
convertEvent.exec();
disconnect(&m_Convert, SIGNAL(finished(int)), this, SLOT(convert()));
disconnect(this, SIGNAL(converted()), &convertEvent, SLOT(quit()));
m_Convert.waitForFinished();
}

QFileSystemModel and QFileSystemWatcher delete from disk

I have a QTreeView which is populated through a reimplementation of QFileSystemModel. As far as I know, QFileSystemModel installs a QFileSystemWatcher on the rootPath. What I'm trying to do is notify in my program when a file is being deleted directicly on the rootPath but i havent found any signal o reimplemented function which provides me that information.
My application upload some files thrugh an ftp connection and when the file is fully uploaded i remove it from the location, so i want a notification from the reimplementation of QFileSystemModel when the file is deleted directicly (not from the remove method or something similar).
I Hope you can help me. I have searched a lot on the web but I cant find anything.
Cheers.
You can use the FileSystemModel's rowsAboutToBeRemoved signal (inherited from QAbstractItemModel).
It will be fired whenever a row is removed from the model. The parent, start and end parameters allow you to get to the filename (in column 0 of the children).
Sample code:
// once you have your model set up:
...
QObject::connect(model, SIGNAL(rowsAboutToBeRemoved(const QModelIndex&, int, int)),
receiver, SLOT(toBeRemoved(const QModelIndex&, int, int)));
...
// in receiver class:
public slots:
void toBeRemoved(const QModelIndex &parent, int start, int end) {
std::cout << start << " -> " << end << std::endl;
std::cout << parent.child(start, 0).data().typeName() << std::endl;
std::cout << qPrintable(parent.child(start, 0).data().toString()) << std::endl;
}
(Using std::cout isn't good practice with Qt I think, this is just to get you started.)
The other aboutToBe... signals from QAbstractItemModel can be used for the other events that happen on the filesystem.

Resources