QObject::Connect no such signal error but cannot see anything wrong :(
-
Hi
My mainwindow class has 2 main objects, a dataDisp and a data Plotter. As a first step all I am trying to do is connect the peak detection in the dataDisp to the mainwindow with signals and slots before I try to connect it to the data display class.
I have attached the mainwindow and dataDisp classes. But I keep getting no such signal errors.
@#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
#include <QtWidgets>
#include "dynamicplots.h"
#include "dispdata.h"
#include "cprServer.h"namespace Ui {
class MainWindow;
}
class dynamicPlots;
class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget parent = 0);
~MainWindow();
void setPlotWindow(dynamicPlots dp);private slots:
void updatePeak(int val, int index);
void on_quitButton_clicked();void on_pbFiles_clicked();
private:
void setUpListener();
dynamicPlots dPlot;
Ui::MainWindow ui;
dispData rawData;
cprServer server;
int newPeak;
int newRecoil;
int newRate;
int newTime;
};#endif // MAINWINDOW_H
#ifndef DISPDATA_H
#define DISPDATA_H
#include <QObject>
#include <vector>
class dispData : public QObject
{
Q_OBJECT
public:
dispData(QObject* parent);
void setStartIndex(int val){startIndex = val;}
void addData(int val, int index);
void updatePeakVals(int val, int index);
int getPeakDepth(){return peakDepth;}
int getTimeMark(){return markTime;}signals:
void newPeakDepth(int peakDepth,int markTime);private:
int startIndex;
int value;
int peakDepth;
int markTime;
int peakRecoil;
int compressionCount;
int compressionRate;
std::vector<int> rawReads;
std::vector<int> rawIndex;};
#endif // DISPDATA_H
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "cprserver.h"MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
const QString IP = "127.0.0.1";
const ushort port = 8100;
ui->setupUi(this);
rawData = new dispData (this);
server = new cprServer(this,rawData,port);
connect(this->rawData,SIGNAL(rawData->newPeakDepth(int,int)),this,SLOT(updatePeak(int, int)));}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::updatePeak(int val,int index)
{
newPeak=val;
newTime=index;
}void MainWindow::on_quitButton_clicked()
{
close();
}void MainWindow::on_pbFiles_clicked()
{
setUpListener();
this->hide();
dPlot->show();}
void MainWindow::setUpListener()
{
const QString IP = "127.0.0.1";
const ushort port = 8100;
QHostAddress host;host.setAddress(IP); //server->setRawData(rawData); if (!server->listen(host,port)) { QMessageBox::critical(this, tr("CPR Server"), tr("Unable to start the server: %1.") .arg(server->errorString())); close(); //qDebug() << "Unable to start server" << server.errorString(); } QString ipAddress=(server->serverAddress()).toString(); qDebug () << "Server started at " << ipAddress ;//go to log
}
void MainWindow::setPlotWindow(dynamicPlots* dp)
{
dPlot = dp;
}@Please somebody help!
-
You have 2 errors:
@
connect(this->rawData,SIGNAL(rawData->newPeakDepth(int,int)), this, SLOT(updatePeak(int, int))); // WRONG!connect(rawData,SIGNAL(newPeakDepth(int,int)), this, SLOT(updatePeak(int, int))); // CORRECT
@And another one is that you have declared "updatePeak" as private slot: I'm acutally not sure, but it might be considered invisible in this situation. If it does not work after you correct error 1, then declare that slot as public.
-
Maybe you should have asked earlier :) Take it easy, Qt is great, but it will require some learning. Have fun and good night :D
-
thanks, it solved my problem too! :)