Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt: No defined slots show up in Signal & Slot Editing

Tags:

I have declared three slots in my mainwindow.h and given their definitions in the implementation file. Here is the MainWindow class:

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

signals:
    void nextImage(int direction);

private slots:
    void updateImage(void);
    void cameraControl(void);
    void cameraStart(void);

private:
    Ui::MainWindow *ui;
    CMUCamera *camera;
    ImageProcessing *process;
    RenderImage *renderImage;
    bool saveImgFlg;
    QString path;
};

Going to mainwindow.ui, I have designed a menu bar for the user interface. There are three QActions, as shown in the figure below: enter image description here

Then, I do the signal and slot editing. But the defined slots (udpateImage, cameraStart and cameraControl) in the header file do not appear in the slot list, as shown in the figure below:

enter image description here

Are there any other steps I missed here or is there something I did wrong? It is also noted QMainWindow, in the framework of which these slots should show up, I guess, is also not displayed in the list.

like image 910
jingweimo Avatar asked Feb 14 '18 21:02

jingweimo


People also ask

How do I connect my signal to my slot Qt?

To connect the signal to the slot, we use QObject::connect(). There are several ways to connect signal and slots. The first is to use function pointers: connect(sender, &QObject::destroyed, this, &MyObject::objectDestroyed);

Can we define a private signal in Qt?

No. Signals cannot be public or private. Qt signals are protected class methods.


1 Answers

I know why that happens. For adding those custom slots, in addition to defining them in header and implementation files, they also should be added in priori by right clicking the QMainWindow, going to change signals and slots and manually adding them in the slot panel. This way is simpler than to code signal&slots.

A similar question has been reported here: my slots don't appear in the signal slot editor

like image 167
jingweimo Avatar answered Oct 11 '22 15:10

jingweimo