PDA

View Full Version : Object::Connect problem



geleven
5th April 2010, 16:37
dear all,
i have some problem when make a connect function which is triggered when a QPushButton was clicked..
the error is

Object::connect: No such slot intervals::writeIntervals(4) in intervals.cpp:21

i give my QPushButton as "Ok", and this is my source code

source for my intervals.h :



#ifndef INTERVALS_H
#define INTERVALS_H

#include <QWidget>
#include <QTextStream>
#include <QFile>
#include <QIODevice>

namespace Ui {
class intervals;
}

class intervals : public QWidget {
Q_OBJECT
public:
intervals(QWidget *parent = 0);
~intervals();
QString readInterval();
void writeInterval(int a);

protected:
void changeEvent(QEvent *e);

private:
Ui::intervals *ui;
QString value;

public slots:
void writeIntervals(int a);

};

#endif


and intervals.cpp



#include "intervals.h"
#include "ui_intervals.h"

intervals::intervals(QWidget *parent) :
QWidget(parent),
ui(new Ui::intervals)
{
ui->setupUi(this);
QFile file ("interval.txt");
if (!file.exists("interval.txt"))
{
this->writeInterval(5);
ui->IntervalEdit->setText(readInterval());
}
else
{
ui->IntervalEdit->setText(readInterval());
}

qDebug("tes");
connect(ui->Ok,SIGNAL(clicked()),this,SLOT(writeIntervals(4))) ;
qDebug("tes2");
}

void intervals::writeInterval(int a)
{
QFile file("interval.txt");
if (file.open(QIODevice::WriteOnly | QIODevice::Text))
{
QTextStream out(&file);
out << a << "\n";
file.close();
}
}


May someone help me with this error?

Wysodava
5th April 2010, 17:07
I'm not a QT expert, but I believe that you can not connect a signal to a slot unless they have the same function parameters.

http://doc.trolltech.com/4.6/signalsandslots.html

{
connect(ui->Ok,SIGNAL(clicked()),this,SLOT(writeIntervalFOUR() ));
}

void intervals::writeIntervalFOUR()
{
writeInterval(4);

}

Also look into QButtonGroup if you want the int parameter

Lykurg
5th April 2010, 17:57
You can't pass values inside a connect statement. But I guess a look at QSignalMapper could be worth for you.

geleven
6th April 2010, 03:38
You can't pass values inside a connect statement. But I guess a look at QSignalMapper could be worth for you.

oh ok... i see the problem. Thanks for your help, Lykurg and Wysodava