In the MainWindow.ui i have a cancel button (no problem with, because i added a close() slot with gui), but if i want to add a myFunction to other button??
You would need to subclass the button in order to add a method. However, you normally don't need to, since you can just add myFunction to MainWindow and connect the clicked() signal to your slot.
/home/maurelio/pgm/qt-sdk/esercizi/FirstGui/mainwindow.h:21: error: ISO C++ forbids declaration of ‘connectAction’ with no type
This error usually happens when you forget to add an #include for the class. However, I don't think connectAction is a class but I guess it's an object, so you probably forgot to specify the class name. e.g.:
...
public slots:
void connectNet();
private:
...
...
public slots:
void connectNet();
private:
QAction *connectAction;
...
To copy to clipboard, switch view to plain text mode
/home/maurelio/pgm/qt-sdk/esercizi/FirstGui/mainwindow.cpp:9: error: ‘connectButton’ was not declared in this scope
This means there's no such connectButton in MainWindow. If you added it in Qt Designer, you would have to use ui->connectButton instead. You could make MainWindow a subclass of Ui::MainWindow. This way you could directly access connectButton without needing to add "ui->".
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtNetwork>
#include "ui_mainwindow.h"
class MainWindow
: public QMainWindow,
private Ui
::MainWindow{
Q_OBJECT
public:
public slots:
void connectNet();
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtNetwork>
#include "ui_mainwindow.h"
class MainWindow : public QMainWindow, private Ui::MainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
public slots:
void connectNet();
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
#include <QtGui>
#include "mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
){
setupUi(this);
connect(connectButton, SIGNAL(clicked()), this, SLOT(connectNet()));
}
void MainWindow::connectNet()
{
//Some Stuff;
}
#include <QtGui>
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
setupUi(this);
connect(connectButton, SIGNAL(clicked()), this, SLOT(connectNet()));
}
void MainWindow::connectNet()
{
//Some Stuff;
}
To copy to clipboard, switch view to plain text mode
Bookmarks