Nominate our 2022 Qt Champions!

why doesn't this connect() function work?

  • I want to use lambda expression in my function,the relations between files and classes like follows:

    MainWIndow w;
    class MainWindow:public QMainWindow
              void initMainWindowUI();
    void MainWindow::initMainWIndowUI()
       QAction *colors = new QAction(ui->menuEdit);
       // this connect() work well 
    void MainWindow::doActionColorGradient()
       QSharedPointer<QDialog> colorGradientParamInputDlg(new QDialog());
       QColor firstColor;
       QToolButton *firstColorButton;
       firstColorButton = new QToolButton();
       // there is nothing happened when I clicked the firstColorButton.
       // what's wrong with my code?
         firstColor = QColorDialog::getColor(QString("first color"));

    Appreciate if you can tell me the solutions .

  • Moderators

    You're using &QToolButton::toggled, but a thats not enabled by default.

    add the following below firstColorButton = new QToolButton()

    firstColorButton ->setCheckable(true);

  • Thank you,But it seems not effct,and I edit




    then it works.
    And I'm learning the differences between triggered and clicked. XD

Log in to reply