2017-10-03 8 views
0

QTで簡単なボタンテキストボックスアプリケーションを作成しようとしています。私はボタンを追加し、私はそれを接続しようとすると4エラーがあります。Qtプッシュボタン接続エラー、Visual Studio 2017

#include "poatelovim.h" 
#include "qmessagebox.h" 
poatelovim::poatelovim(QWidget *parent) 
    : QMainWindow(parent) 
{ 
    ui.setupUi(this); 
    connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(pushButtonClicked())); 
    //ui->pushButton->setText("Hello"); 
} 

//void MyClass::pushButtonClicked() // defined in .h under public/private slots: 
//{ 
    //QMessageBox::information(this, "Information", "Just clicked Ui PushButton"); // #include <QtGui/QMessageBox> 
//} 

The Errors

+0

がこのようにしてください上記のコードのサンプルプロジェクトです: '(UI->プッシュボタン、&のQPushButton ::クリックした、この、&メインウィンドウ:: pushButtonClicked)接続;ないui'' – aghilpro

+1

'ここにポインタがあるので、その要素の要素にアクセスするためには '.'ではなく' - > 'を使います。 –

答えて

0

あなたのスロットに接続信号クリックのためにこれを試してみてください:

connect(ui->pushButton, &QPushButton::clicked, this, &MainWindow::pushButtonClicked); 

またはこのようなあなたの方法:

connect(ui->pushButton, SIGNAL(clicked(bool)), this, SLOT(pushButtonClicked(bool))); 

void MyClass::pushButtonClicked(bool clicked) // defined in .h under public/private slots: 
{ 
    QMessageBox::information(this, "Information", "Just clicked Ui PushButton"); // #include <QtGui/QMessageBox> 
} 

QPushButton signal clicked:この信号は時に放出されますボタンが有効になったら、bu ttonはチェック可能で、チェックされている場合はtrue、チェックされていない場合はfalseです。

これはdownload here.

関連する問題