IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Discussion :

Problème de slot dans Qt

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Août 2009
    Messages
    25
    Détails du profil
    Informations personnelles :
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Août 2009
    Messages : 25
    Par défaut Problème de slot dans Qt
    Bonjour,

    je suis en train de faire un petit widget pour comprendre le fonctionnement de C++/Qt. Je travaille sous Linux avec Netbeans 6.8.

    Ce widget est en fait une sorte d'interface graphique personnelle pour ffmpeg. Les commandes sont stockées dans un fichier commands.xml qui est chargé par le widget.

    J'ai donc créé 3 fichiers :
    • main.cpp

    • form.h

    • form.cpp


    Le problème se situe au niveau d'un slot et je n'arrive pas à trouver la solution même en ayant torturé le problème dans tous les sens ...
    Sur le click d'un QPushButton de mon interface j'obtiens le message suivant:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Object::connect: No such slot form::encodeVideo(std::string fullpathApp2) in form.cpp:119
    Voici mon main.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
     
    #include <QApplication>
    #include "form.h"
     
    int main(int argc,char *argv[])
    {
    	// Get fullpath from arguments
    	std::vector<const char*> v(argv, argv + argc);
    	std::string fullpath = v[0];
    	// Launch widget
    	QApplication mainApplication(argc,argv);
    	form mainForm(fullpath);
    	mainForm.show();
    	mainForm.setWindowIcon(QIcon("logo.png"));
    	return mainApplication.exec();
    }
    Le form.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
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    #include <QObject>
    #include <QString>
    #include <QMessageBox>
    #include <QFileDialog>
    #include <iostream>
    #include <sstream>
    #include <string>
    #include <algorithm>
    #include "tinyxml.h"
    #include "form.h"
     
     
    const std::string textInfile = ("#infile");
    const std::string textOutfile = ("#outfile");
    const std::string textTime = ("#time");
    const std::string idSd = ("sd");
    const std::string idHd = ("hd");
    const std::string idPv = ("pv");
     
     
    form::form(std::string &fullpathApp):QWidget()
    {
    	std::string fullpathApp2 = fullpathApp;
     
    	// Window properties
    	setFixedSize(370,300);
    	setWindowTitle("TYP");
     
    	// Standard Definition section
    	groupboxStandardDefinition = new QGroupBox(this);
    	groupboxStandardDefinition->setTitle("Standard Definition");
    	groupboxStandardDefinition->resize(350,80);
    	groupboxStandardDefinition->move(10,10);
     
    	labelStandardDefinition = new QLabel(groupboxStandardDefinition);
    	labelStandardDefinition->setText("Select file");
    	labelStandardDefinition->move(10,25);
     
    	lineeditStandardDefinition = new QLineEdit(groupboxStandardDefinition);
    	lineeditStandardDefinition->setReadOnly(true);
    	lineeditStandardDefinition->resize(240,20);
    	lineeditStandardDefinition->move(70,20);
     
    	toolbuttonStandardDefinition = new QToolButton(groupboxStandardDefinition);
    	toolbuttonStandardDefinition->setText("...");
    	toolbuttonStandardDefinition->resize(20,20);
    	toolbuttonStandardDefinition->move(320,20);
    	QObject::connect(toolbuttonStandardDefinition,SIGNAL(clicked()),this,SLOT(openFile()));
     
    	labelBasename = new QLabel(groupboxStandardDefinition);
    	labelBasename->setText("Basename");
    	labelBasename->move(10,55);
     
    	lineeditBasename = new QLineEdit(groupboxStandardDefinition);
    	lineeditBasename->resize(240,20);
    	lineeditBasename->move(70,50);
     
    	toolbuttonBasename = new QToolButton(groupboxStandardDefinition);
    	toolbuttonBasename->setText(" ? ");
    	toolbuttonBasename->resize(20,20);
    	toolbuttonBasename->move(320,50);
    	QObject::connect(toolbuttonBasename,SIGNAL(clicked()),this,SLOT(displayHelp()));
     
    	// High Definition section
    	groupboxHighDefinition = new QGroupBox(this);
    	groupboxHighDefinition->setTitle("High Definition");
    	groupboxHighDefinition->resize(350,50);
    	groupboxHighDefinition->move(10,100);
     
    	checkboxHighDefinition = new QCheckBox(groupboxHighDefinition);
    	checkboxHighDefinition->setText("I wanna HD too !");
    	checkboxHighDefinition->move(20,20);
     
    	// Preview section
    	groupboxPreview = new QGroupBox(this);
    	groupboxPreview->setTitle("Preview");
    	groupboxPreview->resize(350,70);
    	groupboxPreview->move(10,160);
     
    	checkboxPreview = new QCheckBox(groupboxPreview);
    	checkboxPreview->setText("I wanna preview too !");
    	checkboxPreview->move(20,20);
     
    	labelPreviewAt = new QLabel(groupboxPreview);
    	labelPreviewAt->setText("Preview at");
    	labelPreviewAt->move(20,50);
     
    	doublespinboxSeconds = new QDoubleSpinBox(groupboxPreview);
    	doublespinboxSeconds->setMaximum(9999);
    	doublespinboxSeconds->resize(60,20);
    	doublespinboxSeconds->move(80,45);
     
    	labelSeconds = new QLabel(groupboxPreview);
    	labelSeconds->setText("seconds");
    	labelSeconds->move(150,50);
     
    	// Encode section
    	progressbarEncode = new QProgressBar(this);
    	progressbarEncode->setTextVisible(false);
    	progressbarEncode->resize(220,15);
    	progressbarEncode->move(20,255);
    	progressbarEncode->setMinimum(0);
    	progressbarEncode->setMaximum(100);
    	//progressbarEncode->setVisible(false);
     
    	pushbuttonEncode = new QPushButton(this);
    	pushbuttonEncode->setText("Encode !");
    	pushbuttonEncode->resize(90,30);
    	pushbuttonEncode->move(270,245);
    	QObject::connect(pushbuttonEncode,SIGNAL(clicked()),this,SLOT(encodeVideo(std::string fullpathApp2)));
     
    	// Version section
    	labelVersion = new QLabel(this);
    	labelVersion->setText("vAlpha");
    	labelVersion->move(4,289);
    }
     
     
    void form::openFile()
    {
    	// Select video file to encode
    	QString fileName = QFileDialog::getOpenFileName(this,tr("Open File"),"/",tr("Video File(*.*)"));
    	lineeditStandardDefinition->setText(fileName);
    }
     
     
    void form::displayHelp()
    {
    	// Display information message
    	QMessageBox::information(this,"About Basename","Basename is used to generate filenames.\nFor example, if you enter \"typ\", output files should be named:\n\"typSD.flv\" \"typHD.flv\" and \"typPV.jpg\".");
    }
     
     
    void form::encodeVideo(std::string fullpathApp)
    {
    	TiXmlDocument fileXml("commands.xml");
    	commands commandsEncode;
    	command tempCommand;
     
    	// Get values from form
    	std::string fullpathFile = lineeditStandardDefinition->text().toStdString();
    	std::string basename = lineeditBasename->text().toStdString();
    	bool needHd = checkboxHighDefinition->isChecked();
    	bool needPv = checkboxPreview->isChecked();
    	double timePreview = doublespinboxSeconds->value();
     
    	// Enable progress bar
    	//progressbarEncode->setValue(0);
    	//progressbarEncode->setVisible(true);
     
    	// Check if a file has been selected
    	if (fullpathFile.size() == 0)
    		QMessageBox::critical(this,"Error","You must select a video file.");
    	else
    	{
     
    		// Check if a basename has been entered
    		if (basename.size() == 0)
    			QMessageBox::critical(this,"Error","You must enter a basename.");
     
    		// Form is correct
    		else
    		{			
     
    			// Detect error in opening XML file
    			if (!fileXml.LoadFile())
    			{
    				QMessageBox::critical(this,"Error","Unable to find the file \"commands.xml\".\nIt should be in the same folder as this application.");
    			}
     
    			else
    			{
    				TiXmlHandle commandHandle(&fileXml);
    				TiXmlElement *commandElement = commandHandle.FirstChildElement().FirstChildElement().Element();
     
    				// Detect error in finding first element in XML file
    				if (!commandElement)
    				{
    					QMessageBox::critical(this,"Error","Unable to read XML data from the file \"commands.xml\".");
    				}
     
    				else
    				{
    					// Extract all fields from XML file
    					while (commandElement)
    					{
    						tempCommand.name = commandElement->Attribute("name");
    						tempCommand.id = commandElement->Attribute("id");
    						tempCommand.pass = atoi(commandElement->Attribute("pass"));
    						tempCommand.commandline = commandElement->GetText();
    						// Save command in the appropriate list
    						if (idSd.compare(tempCommand.id) == 0)
    							commandsEncode.commandsSd.push_back(tempCommand);
    						else if (idHd.compare(tempCommand.id) == 0)
    							commandsEncode.commandsHd.push_back(tempCommand);
    						else if (idPv.compare(tempCommand.id) == 0)
    							commandsEncode.commandsPv.push_back(tempCommand);
    						commandElement = commandElement->NextSiblingElement();
    					}
     
    					// Initialize encode parameters
    					//std::string path = getPath(fullpathFile);
    					int nbrCommandsSd = commandsEncode.commandsSd.size();
    					int nbrCommandsHd = commandsEncode.commandsHd.size();
    					int nbrCommandsPv = commandsEncode.commandsPv.size();
     
    					// Encode SD
    					for(int i=0;i<nbrCommandsSd;i++)
    					{
    						std::string currentCommandLine = commandsEncode.commandsSd[i].commandline;
    						std::string updatedCommandLine = updateCommandVideo(currentCommandLine,fullpathFile,basename,textInfile,textOutfile,idSd);
    						std::cout << updatedCommandLine << std::endl;
    					}
     
    					// Encode HD
    					if (needHd)
    					{
    						for (int i = 0; i < nbrCommandsHd; i++)
    						{
    							std::string currentCommandLine = commandsEncode.commandsHd[i].commandline;
    							std::string updatedCommandLine = updateCommandVideo(currentCommandLine,fullpathFile,basename,textInfile,textOutfile,idHd);
    							std::cout << updatedCommandLine << std::endl;
    						}
    					}
     
    					// Get preview
    					if (needPv)
    					{
    						for (int i = 0; i < nbrCommandsPv; i++)
    						{
    							std::string currentCommandLine = commandsEncode.commandsPv[i].commandline;
    							std::string updatedCommandLine = updateCommandPreview(currentCommandLine,fullpathFile,basename,timePreview,textInfile,textOutfile,textTime,idSd,idPv);
    							std::cout << updatedCommandLine << std::endl;
    						}
    					}
     
     
    				}
    			}
    		}
    	}
    }
     
     
    std::string getPath(std::string filepath)
    {
    	int index = filepath.find_last_of("/\\");
    	return filepath.substr(0,index+1);
    }
     
     
    std::string updateCommandVideo(std::string command,
    						std::string fullpathIn,
    						std::string filename,
    						std::string tagInfile,
    						std::string tagOutfile,
    						std::string tag)
    {
    	// Initialize arguments
    	std::string path = getPath(fullpathIn);
    	std::transform(tag.begin(),tag.end(),tag.begin(),::toupper);   // To uppercase
    	std::string fullpathOut = path + filename + tag;
     
    	// Replace tags #infile and #outfile by fullpath
    	int indexInfile = command.find(tagInfile);
    	command.replace(indexInfile,tagInfile.length(),fullpathIn);
    	int indexOutfile = command.find(tagOutfile);
    	command.replace(indexOutfile,tagOutfile.length(),fullpathOut);
    	return command;
    }
     
     
    std::string updateCommandPreview(std::string command,
    						std::string fullpath,
    						std::string filename,
    						double time,
    						std::string tagInfile,
    						std::string tagOutfile,
    						std::string tagTime,
    						std::string tagSd,
    						std::string tagPv)
    {
    	// Initialize arguments
    	std::string path = getPath(fullpath);
    	std::transform(tagSd.begin(),tagSd.end(),tagSd.begin(),::toupper);   // To uppercase
    	std::string fullpathIn = path + filename + tagSd;
    	std::transform(tagPv.begin(),tagPv.end(),tagPv.begin(),::toupper);   // To uppercase
    	std::string fullpathOut = path + filename + tagPv;
    	std::string timePreview;
    	std::ostringstream temp;
    	temp << time;                                                        // Double to String
    	timePreview = temp.str();
     
    	// Replace tags #infile #outfile and #time by fullpath
    	int indexInfile = command.find(tagInfile);
    	command.replace(indexInfile,tagInfile.length(),fullpathIn);
    	int indexOutfile = command.find(tagOutfile);
    	command.replace(indexOutfile,tagOutfile.length(),fullpathOut);
    	int indexTime = command.find(tagTime);
    	command.replace(indexTime,tagTime.length(),timePreview);
    	return command;
    }
    Le form.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
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    #ifndef _FORM_H
    #define	_FORM_H
     
     
    #include <QApplication>
    #include <QWidget>
    #include <QLabel>
    #include <QLineEdit>
    #include <QToolButton>
    #include <QGroupBox>
    #include <QCheckBox>
    #include <QDoubleSpinBox>
    #include <QProgressBar>
    #include <QPushButton>
    #include "commands.h"
     
     
    class form : public QWidget
    {
    	// Use own slots
    	Q_OBJECT
     
    public:
    	form(std::string &);
     
    public slots:
    	void openFile();
    	void displayHelp();
    	void encodeVideo(std::string fullpathApp);
     
    private:
    	// Standard Definition section
    	QGroupBox *groupboxStandardDefinition;
    	QLabel *labelStandardDefinition;
    	QLineEdit *lineeditStandardDefinition;
    	QToolButton *toolbuttonStandardDefinition;
    	QLabel *labelBasename;
    	QLineEdit *lineeditBasename;
    	QToolButton *toolbuttonBasename;
    	// High Definition section
    	QGroupBox *groupboxHighDefinition;
    	QCheckBox *checkboxHighDefinition;
    	// Preview section
    	QGroupBox *groupboxPreview;
    	QCheckBox *checkboxPreview;
    	QLabel *labelPreviewAt;
    	QDoubleSpinBox *doublespinboxSeconds;
    	QLabel *labelSeconds;
    	// Encode section
    	QProgressBar *progressbarEncode;
    	QPushButton *pushbuttonEncode;
    	// Version section
    	QLabel *labelVersion;
    };
     
     
    std::string getPath(std::string);
     
     
    std::string updateCommandVideo(std::string,
    					 std::string,
    					 std::string,
    					 std::string,
    					 std::string,
    					 std::string);
     
     
    std::string updateCommandPreview(std::string,
    					std::string,
    					std::string,
    					double,
    					std::string,
    					std::string,
    					std::string,
    					std::string,
    					std::string);
     
    #endif
    Globalement je souhaite obtenir le chemin de l'application et le transmettre à encodeVideo(). Si vous avez des remarques globales, des conseils à faire sur le code, je suis preneur !

    Merci pour votre aide.

  2. #2
    Membre très actif
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    688
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 688
    Par défaut
    signal et slot doivent avoir la même signature

  3. #3
    Inactif  


    Homme Profil pro
    Inscrit en
    Novembre 2008
    Messages
    5 288
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Secteur : Santé

    Informations forums :
    Inscription : Novembre 2008
    Messages : 5 288
    Par défaut
    Pour préciser la réponse, dans la ligne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    QObject::connect(pushbuttonEncode,SIGNAL(clicked()),this,SLOT(encodeVideo(std::string fullpathApp2)));
    ton slot (encodeVideo) n'a pas les mêmes paramètres que le signal (clicked) (en fait, il n'est pas nécessaire qu'ils aient la même signature mais que la liste des paramètres du slot corresponde au début ou la totalité de la liste des paramètres du signal)
    Dans ton cas, tu pourrais passer par un slot de form sans paramètre qui envoi au autre signal avec le paramètre string

    Ou tu pourrais aussi simplement récupérer le chemin de l'application avec les fonctions applicationDirPath et applicationFilePath

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Août 2009
    Messages
    25
    Détails du profil
    Informations personnelles :
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Août 2009
    Messages : 25
    Par défaut
    Merci pour vos deux réponse: maintenant je vois le problème !

    Pour l'utilisation de applicationDirPath() ou applicationFilePath(), ce qui m'embête c'est la pharse suivante issue de la documentation:
    On Linux, this function will try to get the path from the /proc file system.
    En effet, je souhaite récupérer le répertoire d'exécution pour ensuite l'utiliser pour charger le fichier de configuration XML à la ligne suivante:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    TiXmlDocument fileXml("commands.xml");
    J'ai remarqué que si j'utilise un chemin relatif comme celui-ci, je ne peux pas charger le fichier. Il faut donc que je mette un chemin de ce type:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    TiXmlDocument fileXml("/home/raphy/Workspace/Netbeans/TYP/dist/Debug/GNU-Linux-x86/commands.xml");
    Et je ne comprends pas pourquoi.

    (J'ai trouvé le très bon tuto pour TinyXML ici: http://khayyam.developpez.com/articles/cpp/tinyxml/)

    Merci.

  5. #5
    Responsable Qt & Livres


    Avatar de dourouc05
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2008
    Messages
    26 772
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Août 2008
    Messages : 26 772
    Par défaut
    Citation Envoyé par Raphyy Voir le message
    (J'ai trouvé le très bon tuto pour TinyXML ici: http://khayyam.developpez.com/articles/cpp/tinyxml/)
    Pourquoi ne pas utiliser du QtXml ? Tu restes ainsi entièrement dans un environnement Qt : http://qt.developpez.com/faq/?page=QtXml
    Vous souhaitez participer aux rubriques Qt (tutoriels, FAQ, traductions) ou HPC ? Contactez-moi par MP.

    Créer des applications graphiques en Python avec PyQt5
    Créer des applications avec Qt 5.

    Pas de question d'ordre technique par MP !

  6. #6
    Membre averti
    Profil pro
    Inscrit en
    Août 2009
    Messages
    25
    Détails du profil
    Informations personnelles :
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Août 2009
    Messages : 25
    Par défaut
    Je connaissais pas, mais je vais essayer ça ! Ça va peut être simplifier pas mal de choses !

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème Signaux/ Slot dans un Thread
    Par Kliffe dans le forum C++
    Réponses: 6
    Dernier message: 15/06/2015, 22h47
  2. Problème d'appel d'un slot dans un QThread
    Par petitclem dans le forum Multithreading
    Réponses: 9
    Dernier message: 20/03/2012, 09h51
  3. problème de police dans un richedit
    Par chtiot dans le forum Composants VCL
    Réponses: 4
    Dernier message: 28/10/2003, 09h48
  4. Réponses: 19
    Dernier message: 27/08/2003, 15h32
  5. problème de guillemets dans une formule shell
    Par dim_italia dans le forum VBA Access
    Réponses: 7
    Dernier message: 18/08/2003, 12h46

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo