2017-07-13 5 views
-2

少し助けてくれたらうれしいです。 トピックにあるので、Q_OBJECT :: connectを実行しようとするとエラーが発生します。 だから私のコードは次のとおりです。 preferences.h:このようなスロットはありませんMainWindow :: showPreferencesWindow()

#include <QDialog> 
#include <QApplication> 
#include <QCoreApplication> 
namespace Ui { 
class Preferences; 
} 

class Preferences : public QDialog 
{ 
    Q_OBJECT 

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


private: 
    Ui::Preferences *ui; 
}; 

preferences.cpp:

#include "preferences.h" 
#include "ui_preferences.h" 

Preferences::Preferences(QWidget *parent) : 
    QDialog(parent), 
    ui(new Ui::Preferences) 
{ 
    ui->setupUi(this); 
} 

Preferences::~Preferences() 
{ 
    delete ui; 
} 

mainwindow.h:

#include "preferences.h" 
#include "addkierowca.h" 


namespace Ui { 
class MainWindow; 
} 

class MainWindow : public QMainWindow 
{ 
    Q_OBJECT 

public: 
    explicit MainWindow(QWidget *parent = 0); 
    ~MainWindow(); 
    Preferences *PreferencesWindow; 
private: 
/* some private methods */ 
void showPreferencesWindow(); 

そして最後にではなく、少なくともmainwindow.cpp:

MainWindow::MainWindow(QWidget *parent) : 
    QMainWindow(parent), 
    ui(new Ui::MainWindow) 
{ 
    ui->setupUi(this); 
    connect(ui->actionUstawiania, SIGNAL(triggered()), this, SLOT(showPreferencesWindow())); 
} 

MainWindow::~MainWindow() 
{ 
    delete ui; 
} 

void MainWindow::showPreferencesWindow() 
{ 
    PreferencesWindow = new Preferences(this); 
    PreferencesWindow->show(); 
    PreferencesWindow->exec(); 
} 

私はどこにでもanwserを見つけることができませんでしたが、私はほとんど同じトピックがあることを知っていますが、それらのどれも私を助けませんでした。 アドバイスありがとうございます。

+0

'slots:'の下にスロットを宣言しようとしましたか?なぜ人々はQt 5の6年後も古い接続構文を使用していますか? – LogicStuff

答えて

0

showPreferencesWindowを接続のスロットとして使用していますので、スロットに接続する必要があります。

変更がに:その時点で

private slots: 
    void showPreferencesWindow(); 

、(メイクファイルで使用される)MOCが正しく動作するために接続するために必要な正しいコードを生成します。

+0

ありがとう、それは助け:) –

関連する問題