PDA

View Full Version : Connect to...without slots...



Peppy
16th October 2009, 14:20
I have code:


int main(int argv, char * argc[])
{
QApplication app(argv,argc);

QWidget* window = new QWidget;

window->setGeometry(QRect(200,200,300,300));
window->setWindowTitle("QFileDialog example");
window->setMaximumSize(300,300);
window->setMinimumSize(300,300);

QPushButton *newFile = new QPushButton("New File Dialog");
newFile->setGeometry(QRect(50,25,250,35));


QPushButton *saveFile = new QPushButton("Save File Dialog");
saveFile->setGeometry(QRect(50,75,250,35));


QGridLayout *layout = new QGridLayout;
layout->addWidget(newFile,0,0,1,1,Qt::AlignHCenter);
layout->addWidget(saveFile,1,0,1,1,Qt::AlignHCenter);

window->connect(...); // ?


window->setLayout(layout);
window->show();


I need to connect button with function ( I don't have class )
something like:

window->connect(newFile,SIGNAL(cliecked()),newFile,SLOT( myImaginedFunc()));
doesn't work because it calls:

QPushButton::myImaginedFunc() which doesn't exist.

DrDonut
16th October 2009, 14:28
You could try to write a new function which would be located underneeth (or above) your main() function.

your connect statement would be something like:

window->connect(newFile,SIGNAL(clicked()),this,SLOT( myImaginedFunc()));

I can imagine that you would have to define 'myImaginedFunc()' as a slot somewhere. I don't know if this can be done in your .cpp file. You might want to create a .h file to do this in.

If this doesn't work, it might be easier to just create a class from which you create your window. The slot can be defined in this class.

Good luck.

lyuts
16th October 2009, 14:47
I think you can create an auxiliary class which will have your function and yhis function will be declared as a slot. In this case your connect statement will be valid.

But in general, I think this is not a normal situation and i think you need to review your application's design.