The problem is that I always get a "No such slot" error in Qt Creator every time I launch the "Settings" window from my main window. I found that Qt is still pretty intuitive, and this concept of signals in the "n" slots seems a bit stretched from just passing through vars or function calls. Basically, I have a menu with the settings parameter, which, when clicked, opens the settings window, which you need to capture double from the user and update var in the main window.
SettingsWindow.h
class SettingsWindow : public QWidget { Q_OBJECT public: SettingsWindow(QWidget *parent = 0); signals: void ValChanged(double newVal); public slots: void Accept(); private: QLineEdit *le1; };
There is an accept button in the settings window that calls Accept (), which emits a ValChanged signal with newVal set as user input in le1 as double.
SettingsWindow.cpp
void SettingsWindow::Accept(){ emit ValChanged(le1->text().toDouble()); this->close(); }
This settings window is called up by the main application window: MainWindow
mainwindow.cpp
class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = 0); public slots: void SetVal(double x); private slots: void NewWindow(); private: double theVal; };
This main window has a menu from which you can select settings. This will create a new window with a field for entering the number.
mainwindow.cpp
void MainWindow::NewWindow() { SettingsWindow *MySettings=new SettingsWindow(this); QObject::connect(MySettings, SIGNAL(ValChanged(double)), this, SLOT(SetVal(double))); MySettings->show(); MySettings->raise(); } void MainWindow::SetVal(double x){ theVal = x; }
I hope that when the settings window opens, the user can enter val in the field, which then emits a ValChanged Signal, which sets the Val value to the value specified by the user. Most of the time I saw a problem with people, not including the Q_OBJECT macro, but I turned it on both times. Any suggestions on why this is not working?