My app hangs when i try custom slots
With that really simple code the app hangs when i click the button, but the examples included in QT works fine, and i don't see differences. I've tryed using different widgets with and without layouts, tryed deriving from QFrame, using "QObject::connect" and "connect" alone, with and without Q_OBJECT macro, but still the same. The only way it works is with an empty slot function. I've tryed with normal SIGNALS and SLOTS and it works. I think it must be a really stupid thing, but i can't see it.
This is the error when windows forces the exit of the program:
The program has unexpectedly finished.
C:\Users\Administador\untitled1-build-desktop-Qt_4_8_1_for_Desktop-_MinGW__Qt_SDK__Debug\debug\untitled1.exe exited with code -1073741819"
class Widget : public QWidget
explicit Widget(QWidget *parent = 0);
#endif // WIDGET_H
Widget::Widget(QWidget *parent) :
QPushButton *button=new QPushButton("HOLA",this);
int main(int argc, char *argv)
QApplication a(argc, argv);
wid.show(); return a.exec();
Try to write such slot:
Looks like "button" isn't initialized.
Edit: the problem is that you redefined your button in constructor. Just write:
@button = new QPushButton("Text", this);@
The actual pointer to the button you are connecting the slot to is lost after the constructor, and the one in the header points to nothing.
Ok, solved. The problem was the second redefinition of the widget. Thanks to both.