PDA

View Full Version : Trouble Connecting QTimeLine to QPushButton Slot that was developed using the Creator



MVivonetto
6th January 2017, 17:53
Hello Everyone!

Im having an issue that is most likely easy to solve but I'm not getting it. I have created a QPushButton in Creator and have developed functions that run perfectly fine using the release() slot. It works flawlessly! My problem now is I want to connect a QTimeLine to the already created release slot. My overall goal is that I have PixMaP Array of acquired images and i want to play them back in My QGraphicsView at variable speeds...basically creating an animation of captured frames...

I am almost finished and can send any single frame at a time to my GraphicsView, change them and so on...but now i would like to animate them by showing all 600 frames in the graphics view one at a time every 150 ms creating a 4 sec animation that is displayed almost in real time since my camera grabs 150 frame per second. Originally i thought a for loop was needed but come to find out the QtimeLine creates the loop which is really cool! Just for ease of understanding..instead of changing frames im just going to get the currentFrame count to display to console..if i can understand and get something as simple as that to work i can take care of the rest.

I am posting my code below..as of now my program tells me:

"QMetaObject::connectSlotsByName: No matching signal for on_play_released(int)"
"QObject::connect: No such slot QPushButton::released(int counting) in ..\mainwindow.cpp:57"
"QObject::connect: (receiver name: 'play')"


As if it does not exist and I'm using Q_Object in my header file as well...

// Namespace for using cout.
using namespace Pylon;
using namespace std;
using namespace Basler_UsbCameraParams;
using namespace cv;
using namespace std;



QVector<QImage> ImageArr;
QVector<QPixmap> PixMapArr;
QTimeLine *timeLine = new QTimeLine(150);
int counting = 0;


MainWindow::MainWindow(QWidget *parent) :

QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

QGraphicsScene *Begin = new QGraphicsScene();
QGraphicsTextItem *startScene = new QGraphicsTextItem;

startScene->setPos(150,70);
startScene->setScale(2);
startScene->setPlainText("Please Ready Camera Position or Begin Acquisition");
Begin->addItem(startScene);
ui->graphicsView->setScene(Begin);


timeLine->setFrameRange(0, 600);
QObject::connect(timeLine, SIGNAL(frameChanged(int)), ui->play, SLOT(on_play_released(int counting)));
QObject::connect(ui->play, SIGNAL(released()), timeLine, SLOT(start()));

}


void MainWindow::on_play_released(int counting)
{

cout << timeLine->currentFrame() << endl;
}

Thank you all who can lend any advice!!!

d_stranz
6th January 2017, 20:49
QObject::connect(timeLine, SIGNAL(frameChanged(int)), ui->play, SLOT(on_play_released(int counting)));

First, this is incorrect syntax for a connect() statement. I assume ui->play points to a QPushButton. QPushButton does not have a slot named "on_play_released()". Your MainWindow does, however. It should be (and please note the use of CODE tags when posting source code):


connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(on_play_released(int)));

Also note that your MainWindow class is derived from QObject, so it is not necessary to qualify connect() with "QObject::" since MainWindow inherits the connect() method from QObject.

As a matter of personal preference, I never create signal / slot connections using Qt Designer, because it "hides" these connections inside the UI file and the code that gets generated by MOC. I prefer to make explicit signal and slot definitions in C++ code, and to make the connections there too. Saves a lot of head-scratching when you can't figure out why a slot is getting executed when there is no obvious code that would do it.

MVivonetto
13th January 2017, 14:13
Thanks d! Sorry I would have responded sooner but I think qtcentre was down for some reason because I could not access it. Anyway, I will definitely use code tags to next time.