2

我想将一些抽象按钮的点击信号连接到同一个插槽。问题是它只适用于一个抽象按钮,当点击其他按钮时没有任何反应。关于失败的任何想法?

我已经检查过信号和插槽之间的连接是否已正确建立。

我还尝试一次只连接一个按钮,看看问题是否将不同的按钮连接到同一个插槽,但问题是它只适用于特定的按钮(带有backroungLbl)。

connect(ui.backgroundLbl, SIGNAL(clicked()), this, SLOT(backgroundClicked()));
connect(ui.cam1mode1Lbl, SIGNAL(clicked()), this, SLOT(backgroundClicked()));
connect(ui.cam1mode2Lbl, SIGNAL(clicked()), this, SLOT(backgroundClicked()));
connect(ui.cam2mode2Lbl, SIGNAL(clicked()), this, SLOT(backgroundClicked()));
connect(ui.cam1mode4Lbl, SIGNAL(clicked()), this, SLOT(backgroundClicked()));
connect(ui.cam2mode4Lbl, SIGNAL(clicked()), this, SLOT(backgroundClicked()));
connect(ui.cam3mode4Lbl, SIGNAL(clicked()), this, SLOT(backgroundClicked()));
connect(ui.cam4mode4Lbl, SIGNAL(clicked()), this, SLOT(backgroundClicked()));
void CIhm::backgroundClicked() {
    printf("background\n");
    if(ui.timePb->isVisible()){
        hideTimeBar();
    } else {
        showTimeBar();
    }
}
//Header
    class CIhm : public QWidget {
        Q_OBJECT
        private:
         class CCamWindow {
         public:
            QAbstractButton* window;
            QAbstractButton* name;

            CCamWindow(){
                window = NULL;
                name = NULL;
            }
            CCamWindow(QAbstractButton* w, QAbstractButton* i = NULL){
                window = w;
                name = i;
            }
         };

        public:
            CIhm();
            ~CIhm();

        private:
            std::map<int, std::vector<QX11EmbedContainer*> > m_ContainerMap;
            std::map<QX11EmbedContainer*, CCamWindow> m_ControlMap;

        private:
            void ConnectSlots();
            void CreateContainers();

        public slots:
            void backgroundClicked();

    };
#include "ihm.h"

CIhm::CIhm (){
    ConnectSlots();
    CreateContainers();

    ui.cam1mode4Lbl->hide();
    ui.cam2mode4Lbl->hide();
    ui.cam3mode4Lbl->hide();
    ui.cam4mode4Lbl->hide();
    ui.cam1mode4nameLbl->hide();
    ui.cam2mode4nameLbl->hide();
    ui.cam3mode4nameLbl->hide();
    ui.cam4mode4nameLbl->hide();
    ui.cam1mode1Lbl->hide();
    ui.cam1mode1nameLbl->hide();
}

void CIhm::ConnectSlots(){
    connect(ui.backgroundLbl, SIGNAL(clicked()), this, SLOT(backgroundClicked()));
    connect(ui.cam1mode1Lbl, SIGNAL(clicked()), this, SLOT(backgroundClicked()));
    connect(ui.cam1mode2Lbl, SIGNAL(clicked()), this, SLOT(backgroundClicked()));
    connect(ui.cam2mode2Lbl, SIGNAL(clicked()), this, SLOT(backgroundClicked()));
    connect(ui.cam1mode4Lbl, SIGNAL(clicked()), this, SLOT(backgroundClicked()));
    connect(ui.cam2mode4Lbl, SIGNAL(clicked()), this, SLOT(backgroundClicked()));
    connect(ui.cam3mode4Lbl, SIGNAL(clicked()), this, SLOT(backgroundCLicked()));
    connect(ui.cam4mode4Lbl, SIGNAL(clicked()), this, SLOT(backgroundClicked()));
}

void CIhm::CreateContainers(){

    std::vector<QX11EmbedContainer*> singleContainer;
    singleContainer.push_back(new QX11EmbedContainer(this));
    singleContainer[0]->setGeometry(ui.cam1mode1Lbl->geometry().x(), ui.cam1mode1Lbl->geometry().y(), ui.cam1mode1Lbl->geometry().width()-1, ui.cam1mode1Lbl->geometry().height()-1);
    m_ControlMap[singleContainer[0]] = CCamWindow(ui.cam1mode1Lbl, ui.cam1mode1nameLbl);
    m_ContainerMap[1] = singleContainer;


    std::vector<QX11EmbedContainer*> doubleContainer;
    doubleContainer.push_back(new QX11EmbedContainer(this));
    doubleContainer[0]->setGeometry(ui.cam1mode2Lbl->geometry().x(), ui.cam1mode2Lbl->geometry().y(), ui.cam1mode2Lbl->geometry().width()-1, ui.cam1mode2Lbl->geometry().height()-1);
    m_ControlMap[doubleContainer[0]] = CCamWindow(ui.cam1mode2Lbl, ui.cam1mode2nameLbl);
    doubleContainer.push_back(new QX11EmbedContainer(this));
    doubleContainer[1]->setGeometry(ui.cam2mode2Lbl->geometry().x(), ui.cam2mode2Lbl->geometry().y(), ui.cam2mode2Lbl->geometry().width()-1, ui.cam2mode2Lbl->geometry().height()-1);
    m_ControlMap[doubleContainer[1]] = CCamWindow(ui.cam2mode2Lbl, ui.cam2mode2nameLbl);
    m_ContainerMap[2] = doubleContainer;


    std::vector<QX11EmbedContainer*> quadContainer;
    quadContainer.push_back(new QX11EmbedContainer(this));
    quadContainer[0]->setGeometry(ui.cam1mode4Lbl->geometry().x(), ui.cam1mode4Lbl->geometry().y(), ui.cam1mode4Lbl->geometry().width()-1, ui.cam1mode4Lbl->geometry().height()-1);
    m_ControlMap[quadContainer[0]] = CCamWindow(ui.cam1mode4Lbl, ui.cam1mode4nameLbl);
    quadContainer.push_back(new QX11EmbedContainer(this));
    quadContainer[1]->setGeometry(ui.cam2mode4Lbl->geometry().x(), ui.cam2mode4Lbl->geometry().y(), ui.cam2mode4Lbl->geometry().width()-1, ui.cam2mode4Lbl->geometry().height()-1);
    m_ControlMap[quadContainer[1]] = CCamWindow(ui.cam2mode4Lbl, ui.cam2mode4nameLbl);
    quadContainer.push_back(new QX11EmbedContainer(this));
    quadContainer[2]->setGeometry(ui.cam3mode4Lbl->geometry().x(), ui.cam3mode4Lbl->geometry().y(), ui.cam3mode4Lbl->geometry().width()-1, ui.cam3mode4Lbl->geometry().height()-1);
    m_ControlMap[quadContainer[2]] = CCamWindow(ui.cam3mode4Lbl, ui.cam3mode4nameLbl);
    quadContainer.push_back(new QX11EmbedContainer(this));
    quadContainer[3]->setGeometry(ui.cam4mode4Lbl->geometry().x(), ui.cam4mode4Lbl->geometry().y(), ui.cam4mode4Lbl->geometry().width()-1, ui.cam4mode4Lbl->geometry().height()-1);
    m_ControlMap[quadContainer[3]] = CCamWindow(ui.cam4mode4Lbl, ui.cam4mode4nameLbl);
    m_ContainerMap[4] = quadContainer;
}

void CIhm::backgroundClicked() {
    printf("background\n");
        if(ui.timePb->isVisible()){
            hideTimeBar();
        } else {
            showTimeBar();
        }
}
4

0 回答 0