Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 7

Qt-interest Archive, August 2006
Slots not called


Message 1 in thread

Hi all,

I am new to Qt 4.1.4 on WinXP and MinGW.
For the first time i tried to use Designer for the GUI.

I have a few buttons. I connected the clicked() signal of loadButton and 
saveButton to the slots open() and save() respectively.

But those slots never seem to get called.
What am i missing?


Here is the code:

///////// mainwidget.h ///////////
#ifndef MAINWIDGET_H_
#define MAINWIDGET_H_

#include "ui_mainwidget.h"

#include <QWidget>

class MyMainWidget : public QWidget, Ui::mainWidget
{
	Q_OBJECT
	
	public:
	MyMainWidget(QWidget * parent = 0, Qt::WFlags f = 0 );	
	
	private slots:
	
	void open();
	void save();
};

#endif /*MAINWIDGET_H_*/

//////////// mainWdiget.cpp //////////////
#include "mainwidget.h"

MyMainWidget::MyMainWidget(QWidget * parent, Qt::WFlags f)
	: QWidget(parent,f)
{
	setupUi(this);	
	
	connect(loadButton,SIGNAL(clicked()),this,SLOT(open()));
	connect(saveButton,SIGNAL(clicked()),this,SLOT(save()));
}

void MyMainWidget::open()
{
	qDebug("open()");	
}

void MyMainWidget::save()
{
	qDebug("save()");	
}

/////////////// main.cpp ///////////

#include "mainwidget.h"
#include "ui_mainwidget.h"

#include <QApplication>

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

	Ui::mainWidget wUi;	
	MyMainWidget * w = new MyMainWidget();
	
	wUi.setupUi(w);
	w->show();
	
	return app.exec();	
}


/////////////// ui_mainwidget.h generated by uic /////////
#ifndef UI_MAINWIDGET_H
#define UI_MAINWIDGET_H

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDoubleSpinBox>
#include <QtGui/QHBoxLayout>
#include <QtGui/QPushButton>
#include <QtGui/QSpacerItem>
#include <QtGui/QTableView>
#include <QtGui/QVBoxLayout>
#include <QtGui/QWidget>

class Ui_mainWidget
{
public:
    QWidget *layoutWidget;
    QVBoxLayout *vboxLayout;
    QTableView *tableView;
    QHBoxLayout *hboxLayout;
    QDoubleSpinBox *offsetSpinBox;
    QPushButton *offsetButton;
    QHBoxLayout *hboxLayout1;
    QPushButton *loadButton;
    QPushButton *saveButton;
    QSpacerItem *spacerItem;
    QPushButton *quitButton;

    void setupUi(QWidget *mainWidget)
    {
    mainWidget->setObjectName(QString::fromUtf8("mainWidget"));
    mainWidget->resize(QSize(308, 
309).expandedTo(mainWidget->minimumSizeHint()));
    layoutWidget = new QWidget(mainWidget);
    layoutWidget->setObjectName(QString::fromUtf8("layoutWidget"));
    layoutWidget->setGeometry(QRect(21, 21, 258, 260));
    vboxLayout = new QVBoxLayout(layoutWidget);
    vboxLayout->setSpacing(6);
    vboxLayout->setMargin(0);
    vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
    tableView = new QTableView(layoutWidget);
    tableView->setObjectName(QString::fromUtf8("tableView"));

    vboxLayout->addWidget(tableView);

    hboxLayout = new QHBoxLayout();
    hboxLayout->setSpacing(6);
    hboxLayout->setMargin(0);
    hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
    offsetSpinBox = new QDoubleSpinBox(layoutWidget);
    offsetSpinBox->setObjectName(QString::fromUtf8("offsetSpinBox"));
    offsetSpinBox->setMaximum(100);
    offsetSpinBox->setMinimum(-100);
    offsetSpinBox->setSingleStep(0.1);

    hboxLayout->addWidget(offsetSpinBox);

    offsetButton = new QPushButton(layoutWidget);
    offsetButton->setObjectName(QString::fromUtf8("offsetButton"));

    hboxLayout->addWidget(offsetButton);


    vboxLayout->addLayout(hboxLayout);

    hboxLayout1 = new QHBoxLayout();
    hboxLayout1->setSpacing(6);
    hboxLayout1->setMargin(0);
    hboxLayout1->setObjectName(QString::fromUtf8("hboxLayout1"));
    loadButton = new QPushButton(layoutWidget);
    loadButton->setObjectName(QString::fromUtf8("loadButton"));
 
loadButton->setIcon(QIcon(QString::fromUtf8("G:/tools/IconsNSG4070/nuvola-1.0/nuvola/32x32/actions/fileopen.png")));
    loadButton->setAutoRepeat(true);

    hboxLayout1->addWidget(loadButton);

    saveButton = new QPushButton(layoutWidget);
    saveButton->setObjectName(QString::fromUtf8("saveButton"));
 
saveButton->setIcon(QIcon(QString::fromUtf8("G:/tools/IconsNSG4070/nuvola-1.0/nuvola/32x32/actions/filesave.png")));

    hboxLayout1->addWidget(saveButton);

    spacerItem = new QSpacerItem(61, 26, QSizePolicy::Expanding, 
QSizePolicy::Minimum);

    hboxLayout1->addItem(spacerItem);

    quitButton = new QPushButton(layoutWidget);
    quitButton->setObjectName(QString::fromUtf8("quitButton"));
 
quitButton->setIcon(QIcon(QString::fromUtf8("g:/tools/IconsNSG4070/nuvola-1.0/nuvola/32x32/actions/exit.png")));

    hboxLayout1->addWidget(quitButton);


    vboxLayout->addLayout(hboxLayout1);

    retranslateUi(mainWidget);

    QMetaObject::connectSlotsByName(mainWidget);
    } // setupUi

    void retranslateUi(QWidget *mainWidget)
    {
    mainWidget->setWindowTitle(QApplication::translate("mainWidget", 
"Form", 0, QApplication::UnicodeUTF8));
    offsetSpinBox->setPrefix(QApplication::translate("mainWidget", "", 0, 
QApplication::UnicodeUTF8));
    offsetButton->setText(QApplication::translate("mainWidget", "Add 
Offset", 0, QApplication::UnicodeUTF8));
    loadButton->setText(QApplication::translate("mainWidget", "Load", 0, 
QApplication::UnicodeUTF8));
    loadButton->setShortcut(QApplication::translate("mainWidget", "", 0, 
QApplication::UnicodeUTF8));
    saveButton->setText(QApplication::translate("mainWidget", "&Save", 0, 
QApplication::UnicodeUTF8));
    quitButton->setText(QApplication::translate("mainWidget", "&Quit", 0, 
QApplication::UnicodeUTF8));
    Q_UNUSED(mainWidget);
    } // retranslateUi

};

namespace Ui {
    class mainWidget: public Ui_mainWidget {};
} // namespace Ui

#endif // UI_MAINWIDGET_H




Best,

Andre

--
 [ signature omitted ] 

Message 2 in thread

Hi,

they are probably called, but you cannot see the qDebug output, since it 
is sent to stdDebug on Windoze. 
Either put "console"-flag  to CONFIG in your pro file (then you get it on 
the console) or use some program to capture stdDebug.

Regards,
Malte


Andre Haupt <ahaupt@xxxxxxxxxxxxx> schrieb am 31.08.2006 11:59:47:

> Hi all,
> 
> I am new to Qt 4.1.4 on WinXP and MinGW.
> For the first time i tried to use Designer for the GUI.
> 
> I have a few buttons. I connected the clicked() signal of loadButton and 

> saveButton to the slots open() and save() respectively.
> 
> But those slots never seem to get called.
> What am i missing?
> 
> 
> Here is the code:
> 
> ///////// mainwidget.h ///////////
> #ifndef MAINWIDGET_H_
> #define MAINWIDGET_H_
> 
> #include "ui_mainwidget.h"
> 
> #include <QWidget>
> 
> class MyMainWidget : public QWidget, Ui::mainWidget
> {
>    Q_OBJECT
> 
>    public:
>    MyMainWidget(QWidget * parent = 0, Qt::WFlags f = 0 ); 
> 
>    private slots:
> 
>    void open();
>    void save();
> };
> 
> #endif /*MAINWIDGET_H_*/
> 
> //////////// mainWdiget.cpp //////////////
> #include "mainwidget.h"
> 
> MyMainWidget::MyMainWidget(QWidget * parent, Qt::WFlags f)
>    : QWidget(parent,f)
> {
>    setupUi(this); 
> 
>    connect(loadButton,SIGNAL(clicked()),this,SLOT(open()));
>    connect(saveButton,SIGNAL(clicked()),this,SLOT(save()));
> }
> 
> void MyMainWidget::open()
> {
>    qDebug("open()"); 
> }
> 
> void MyMainWidget::save()
> {
>    qDebug("save()"); 
> }
> 
> /////////////// main.cpp ///////////
> 
> #include "mainwidget.h"
> #include "ui_mainwidget.h"
> 
> #include <QApplication>
> 
> int main (int argc, char** argv)
> {
>    QApplication app(argc,argv);
> 
>    Ui::mainWidget wUi; 
>    MyMainWidget * w = new MyMainWidget();
> 
>    wUi.setupUi(w);
>    w->show();
> 
>    return app.exec(); 
> }
> 
> 
> /////////////// ui_mainwidget.h generated by uic /////////
> #ifndef UI_MAINWIDGET_H
> #define UI_MAINWIDGET_H
> 
> #include <QtCore/QVariant>
> #include <QtGui/QAction>
> #include <QtGui/QApplication>
> #include <QtGui/QButtonGroup>
> #include <QtGui/QDoubleSpinBox>
> #include <QtGui/QHBoxLayout>
> #include <QtGui/QPushButton>
> #include <QtGui/QSpacerItem>
> #include <QtGui/QTableView>
> #include <QtGui/QVBoxLayout>
> #include <QtGui/QWidget>
> 
> class Ui_mainWidget
> {
> public:
>     QWidget *layoutWidget;
>     QVBoxLayout *vboxLayout;
>     QTableView *tableView;
>     QHBoxLayout *hboxLayout;
>     QDoubleSpinBox *offsetSpinBox;
>     QPushButton *offsetButton;
>     QHBoxLayout *hboxLayout1;
>     QPushButton *loadButton;
>     QPushButton *saveButton;
>     QSpacerItem *spacerItem;
>     QPushButton *quitButton;
> 
>     void setupUi(QWidget *mainWidget)
>     {
>     mainWidget->setObjectName(QString::fromUtf8("mainWidget"));
>     mainWidget->resize(QSize(308, 
> 309).expandedTo(mainWidget->minimumSizeHint()));
>     layoutWidget = new QWidget(mainWidget);
>     layoutWidget->setObjectName(QString::fromUtf8("layoutWidget"));
>     layoutWidget->setGeometry(QRect(21, 21, 258, 260));
>     vboxLayout = new QVBoxLayout(layoutWidget);
>     vboxLayout->setSpacing(6);
>     vboxLayout->setMargin(0);
>     vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
>     tableView = new QTableView(layoutWidget);
>     tableView->setObjectName(QString::fromUtf8("tableView"));
> 
>     vboxLayout->addWidget(tableView);
> 
>     hboxLayout = new QHBoxLayout();
>     hboxLayout->setSpacing(6);
>     hboxLayout->setMargin(0);
>     hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
>     offsetSpinBox = new QDoubleSpinBox(layoutWidget);
>     offsetSpinBox->setObjectName(QString::fromUtf8("offsetSpinBox"));
>     offsetSpinBox->setMaximum(100);
>     offsetSpinBox->setMinimum(-100);
>     offsetSpinBox->setSingleStep(0.1);
> 
>     hboxLayout->addWidget(offsetSpinBox);
> 
>     offsetButton = new QPushButton(layoutWidget);
>     offsetButton->setObjectName(QString::fromUtf8("offsetButton"));
> 
>     hboxLayout->addWidget(offsetButton);
> 
> 
>     vboxLayout->addLayout(hboxLayout);
> 
>     hboxLayout1 = new QHBoxLayout();
>     hboxLayout1->setSpacing(6);
>     hboxLayout1->setMargin(0);
>     hboxLayout1->setObjectName(QString::fromUtf8("hboxLayout1"));
>     loadButton = new QPushButton(layoutWidget);
>     loadButton->setObjectName(QString::fromUtf8("loadButton"));
> 
> loadButton->setIcon(QIcon(QString::fromUtf8("G:
> /tools/IconsNSG4070/nuvola-1.0/nuvola/32x32/actions/fileopen.png")));
>     loadButton->setAutoRepeat(true);
> 
>     hboxLayout1->addWidget(loadButton);
> 
>     saveButton = new QPushButton(layoutWidget);
>     saveButton->setObjectName(QString::fromUtf8("saveButton"));
> 
> saveButton->setIcon(QIcon(QString::fromUtf8("G:
> /tools/IconsNSG4070/nuvola-1.0/nuvola/32x32/actions/filesave.png")));
> 
>     hboxLayout1->addWidget(saveButton);
> 
>     spacerItem = new QSpacerItem(61, 26, QSizePolicy::Expanding, 
> QSizePolicy::Minimum);
> 
>     hboxLayout1->addItem(spacerItem);
> 
>     quitButton = new QPushButton(layoutWidget);
>     quitButton->setObjectName(QString::fromUtf8("quitButton"));
> 
> quitButton->setIcon(QIcon(QString::fromUtf8("g:
> /tools/IconsNSG4070/nuvola-1.0/nuvola/32x32/actions/exit.png")));
> 
>     hboxLayout1->addWidget(quitButton);
> 
> 
>     vboxLayout->addLayout(hboxLayout1);
> 
>     retranslateUi(mainWidget);
> 
>     QMetaObject::connectSlotsByName(mainWidget);
>     } // setupUi
> 
>     void retranslateUi(QWidget *mainWidget)
>     {
>     mainWidget->setWindowTitle(QApplication::translate("mainWidget", 
> "Form", 0, QApplication::UnicodeUTF8));
>     offsetSpinBox->setPrefix(QApplication::translate("mainWidget", "", 
0, 
> QApplication::UnicodeUTF8));
>     offsetButton->setText(QApplication::translate("mainWidget", "Add 
> Offset", 0, QApplication::UnicodeUTF8));
>     loadButton->setText(QApplication::translate("mainWidget", "Load", 0, 

> QApplication::UnicodeUTF8));
>     loadButton->setShortcut(QApplication::translate("mainWidget", "", 0, 

> QApplication::UnicodeUTF8));
>     saveButton->setText(QApplication::translate("mainWidget", "&Save", 
0, 
> QApplication::UnicodeUTF8));
>     quitButton->setText(QApplication::translate("mainWidget", "&Quit", 
0, 
> QApplication::UnicodeUTF8));
>     Q_UNUSED(mainWidget);
>     } // retranslateUi
> 
> };
> 
> namespace Ui {
>     class mainWidget: public Ui_mainWidget {};
> } // namespace Ui
> 
> #endif // UI_MAINWIDGET_H
> 
> 
> 
> 
> Best,
> 
> Andre
> 
> --
> 
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx 
> with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 

--
 [ signature omitted ] 

Message 3 in thread

--On Donnerstag, 31. August 2006 12:05 +0200 Malte Witt 
<malte.witt@xxxxxxxxxxxxx> wrote:

>
> Hi,
>
> they are probably called, but you cannot see the qDebug output, since it
> is sent to stdDebug on Windoze.
> Either put "console"-flag  to CONFIG in your pro file (then you get it on
> the console) or use some program to capture stdDebug.
>

Sorry, forgot to mention that my project file already contains
CONFIG += console and qDebug() in general works.
So this doesnt seem to be the reason.

Best,

Andre

--
 [ signature omitted ] 

Message 4 in thread

Hmm ok ... was just a blind guess. I have another one, if you don't mind:

You are calling setupUi twice - once in your constructor of the mainWidget 
and once in your main(). You should remove the Ui-Stuff from the main() I 
guess.

Regards,
Malte


Andre Haupt <ahaupt@xxxxxxxxxxxxx> schrieb am 31.08.2006 12:10:10:

> --On Donnerstag, 31. August 2006 12:05 +0200 Malte Witt 
> <malte.witt@xxxxxxxxxxxxx> wrote:
> 
> >
> > Hi,
> >
> > they are probably called, but you cannot see the qDebug output, since 
it
> > is sent to stdDebug on Windoze.
> > Either put "console"-flag  to CONFIG in your pro file (then you get it 
on
> > the console) or use some program to capture stdDebug.
> >
> 
> Sorry, forgot to mention that my project file already contains
> CONFIG += console and qDebug() in general works.
> So this doesnt seem to be the reason.
> 
> Best,
> 
> Andre
> 
> --
> 
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx 
> with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 

--
 [ signature omitted ] 

Message 5 in thread

> But those slots never seem to get called.
> What am i missing?

I don't know. I just noticed you use setupUi twice:

> MyMainWidget::MyMainWidget(QWidget * parent, Qt::WFlags f)
> 	: QWidget(parent,f)
> {
> 	setupUi(this);	/******************* HERE *******************/
> 	
> 	connect(loadButton,SIGNAL(clicked()),this,SLOT(open()));
> 	connect(saveButton,SIGNAL(clicked()),this,SLOT(save()));
> }
> [...]
> int main (int argc, char** argv)
> {
> 	QApplication app(argc,argv);
> 
> 	Ui::mainWidget wUi;	
> 	MyMainWidget * w = new MyMainWidget();
> 	
> 	wUi.setupUi(w); /******************* HERE *******************/
> 	w->show();

I am not even sure where the '{load,save}Button' in the C'tor come
from...

Andre'

--
 [ signature omitted ]