kja
17th November 2010, 07:13
Hi,
Is it possible to get your slots to call other functions from other classes?
I want to have my main qwidget's buttons call on a class I made that plots some QWTplots. This is what I'm working on now, but I am afraid I am going about the slot implementation the wrong way
class myPlot : public QwtPlot
{
...
myPlot(){}
void loadFile( char * fn )
{
//a function that opens a file...
}
void plot( double st, double end )
{
//loads the data and assigns it to a curve...
}
};
class myCanvas : public QWidget
{
Q_OBJECT
public:
myCanvas (QWidget * parent = 0);
public Q_SLOTS:
void enterFile();
void addFile();
void makePlot();
};
myCanvas::myCanvas(QWidget *parent):QWidget(parent)
{
....
myPlot *plot = new myPlot(); //is this even close to right?
connect(pushbutton, SIGNAL(clicked()), this, SLOT(enterFile()));
connect(pushbutton, SIGNAL(clicked()), this, SLOT(addFile()));
connect(pushbutton, SIGNAL(clicked()), this, SLOT(makePlot()));
....
}
void myCanvas::enterFile()
{
QString theText = lineedit->text(); ///this works
FileName = qstrdup( theText.toLatin1() );
}
void myCanvas::addFile()
{
plot->loadFile(FileName); //error plot undeclared identifier
}
void myCanvas::slotButtonPlots()
{
myPlot::plot(1264377600, 1288974375.51);
//error: illegal call of non-static member function
// something like this maybe?
}
Any ideas how I can call these these myPlot functions with myCanvas, or is that impossible?
Do I have to make new functions in myCanvas in order for the slots to work?
Thanks a lot!
Is it possible to get your slots to call other functions from other classes?
I want to have my main qwidget's buttons call on a class I made that plots some QWTplots. This is what I'm working on now, but I am afraid I am going about the slot implementation the wrong way
class myPlot : public QwtPlot
{
...
myPlot(){}
void loadFile( char * fn )
{
//a function that opens a file...
}
void plot( double st, double end )
{
//loads the data and assigns it to a curve...
}
};
class myCanvas : public QWidget
{
Q_OBJECT
public:
myCanvas (QWidget * parent = 0);
public Q_SLOTS:
void enterFile();
void addFile();
void makePlot();
};
myCanvas::myCanvas(QWidget *parent):QWidget(parent)
{
....
myPlot *plot = new myPlot(); //is this even close to right?
connect(pushbutton, SIGNAL(clicked()), this, SLOT(enterFile()));
connect(pushbutton, SIGNAL(clicked()), this, SLOT(addFile()));
connect(pushbutton, SIGNAL(clicked()), this, SLOT(makePlot()));
....
}
void myCanvas::enterFile()
{
QString theText = lineedit->text(); ///this works
FileName = qstrdup( theText.toLatin1() );
}
void myCanvas::addFile()
{
plot->loadFile(FileName); //error plot undeclared identifier
}
void myCanvas::slotButtonPlots()
{
myPlot::plot(1264377600, 1288974375.51);
//error: illegal call of non-static member function
// something like this maybe?
}
Any ideas how I can call these these myPlot functions with myCanvas, or is that impossible?
Do I have to make new functions in myCanvas in order for the slots to work?
Thanks a lot!