PDA

View Full Version : Slot not working



dayrinni
2nd September 2006, 04:29
Hello, I am writing a qt program in VS 6.0.

I have a window with a button on it. When the button is pressed it will create a file dialog box. I have placed the window and wrote the code to hopefully do this. I have the class that contains the slot.



class Panel : public QWidget
{

public:
Panel(QWidget *parent = 0, QObject *app = 0);
...methods

private slots:
void openFieldDialog();

private:
...variables
};


Here is the code for the slot:


void Panel::openFieldDialog()
{
...code
}

Here is the line where I use the connect for it:


QPushButton *loadFile = new QPushButton("Load File", mainFrame);
//this = Panel
QObject::connect(loadFile, SIGNAL(clicked()), this, SLOT(Panel::openFieldDialog()));

I then compile and build in VS 6.0 and run the program. Nothing happens when I click on the button and on the console window that appears this is seen (it is present before I click):
Object::connect: No such slot QWidget::Panel::openFieldDialog()

I have tried numerous other things, such as openFieldDialog() instead of Panel::..., etc.

Any ideas?

Thank you!!

PS:

Also is there a way to get qmake to work with the makefile for VS 6.0? I'd rather to have all of my compiling done with 1 thing.

munna
2nd September 2006, 06:00
Whenever you have either signal or slot used in a class you need to add the Q_OBJECT macro.

Your class should be something like




class Panel : public QWidget
{

Q_OBJECT

public:
Panel(QWidget *parent = 0, QObject *app = 0);
...methods
private slots:
void openFieldDialog();
private:
...variables
};

dayrinni
2nd September 2006, 06:02
Hmm, I cannot compile if Q_OBJECT is in present in VS 6.0.

I haven't figured out how to make it work with VS 6.0. Do you know how I can incorprate the qmake into VS ?

munna
2nd September 2006, 06:14
This (http://doc.trolltech.com/4.1/moc.html) might help

wysota
2nd September 2006, 13:47
You might want to remove the namespace ("Panel::") from the slot name. I'm not sure if the slot normaliser is able to accept that as a proper slot name. You still have to provide Q_OBJECT of course...

sunil.thaha
4th September 2006, 06:20
If you are using VS 6.0

Do you have the Qt plugins installed.

If so
Open the header file and click on the moc tool button, This will add a moc_filename.cpp to the project.