Bonjour

Je suis en train de développé un chat avec Qt Creator et Qt Designer.

J'ai créer une interface graphique avec Qt Designer et 2 fichier cpp : client.cpp, mainwindows.cpp

Mon problème, c'est que je n'arrive pas à connecter un bouton de l'interface avec un slot issue d'une autre classe.

Mon code :

client.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef CLIENT_H
#define CLIENT_H
 
 
class QTcpSocket;
 
class client
{
 
public:
    client();
 
private slots:
        void connexion();
 
private:
       QTcpSocket *socket ;
};
 
#endif // CLIENT_H
client.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "client.h"
 
 
client::client()
{
}
 
//Connexion à 1 serveur
void MainWindow::connexion()
{
    QString IPHost;
    IPHost = Ui::host;
    socket->connectToHost("IPHost", "4000");
    if (!socket)
    {
        cout<<"1"<<endl;
    }
}
mainwindows.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
 
#include <QMainWindow>
#include <QDialog>
 
namespace Ui
{
class MainWindow;
}
 
class MainWindow : public QMainWindow
{
    Q_OBJECT
 
public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();
 
private slots:
    void fenetre_chat();
 
private:
    void affichertexte();
    Ui::MainWindow *ui;
};
 
#endif // MAINWINDOW_H
mainwindow.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "client.h"
 
//Affichage de la fenêtre principale
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
 
    ui->setupUi(this);
    //connect(ui->chat_bouton, SIGNAL(clicked()), this,  SLOT(fenetre_chat()));
    connect(ui->connexion_bouton, SIGNAL(clicked()), client, SLOT( connexion() ) );
}
 
MainWindow::~MainWindow()
{
    delete ui;
}
 
void MainWindow::fenetre_chat()
{
     QDialog FENChat ;
     FENChat.show();
}
 
void MainWindow::affichertexte()
{
   ui->texte->setText("allo");
}
Je pense que l'erreur vient de la
connect(ui->connexion_bouton, SIGNAL(clicked()), client, SLOT( connexion() ) );

Merci de votre aide !