Partage
  • Partager sur Facebook
  • Partager sur Twitter

[Qt] ouvertture d'une fenetre

probleme

Sujet résolu
    24 avril 2008 à 15:45:25

    Bonjour

    Voici la situation:

    J'ai 2 classes qui herite toutes les 2 de QWidget.
    Dans un des slots de ma premiere fenetre il y a le code suivant:

    fenetre2 window2;
    window2.show();

    Le probleme et que sa compile bien mais la fenetre n'aparait pas... enfin si mais il faut cliquer plein de fois et on peut voir la fenetre aparaitre et disparaitre instantanement...

    Copmment je peut faire pour resoudre ce probleme?
    • Partager sur Facebook
    • Partager sur Twitter
    Anonyme
      24 avril 2008 à 16:06:18

      en fait, la windows2 a une portée limité au slot, donc dés qu'il est finit, la fenêtre est détruite.
      • Partager sur Facebook
      • Partager sur Twitter
        24 avril 2008 à 16:41:56

        donc en gros de doit faire une metode qui n'est pas un slot


        EDIT: sa marche toujours pas.. pouvez vous me donner la solution
        • Partager sur Facebook
        • Partager sur Twitter
        Anonyme
          24 avril 2008 à 16:49:33

          Non, car la portée dans un slot et dans une methode est la meme (que celle des fonctions).
          Donc en fait tu doit stocker ta fenêtre autre par, en attribut de la classe par exemple, et appeler la fonction window2.show(); dans le slot.
          • Partager sur Facebook
          • Partager sur Twitter
            24 avril 2008 à 16:54:55

            sa marche toujours pas:

            en gros je declare la classe de la fenetre2 dans le .h de la fenetre1, exe:

            fenetre2 *windows2;

            et dans le slot de la fenetre1 je met:

            windows2->show();

            sa me met sa comme erreur:

            redefinition of `class janela'
            previous definition of `class janela'
            confused by earlier errors, bailing out
            • Partager sur Facebook
            • Partager sur Twitter
            Anonyme
              24 avril 2008 à 16:57:16

              enleve le pointeur
              • Partager sur Facebook
              • Partager sur Twitter
                24 avril 2008 à 16:59:23

                sa compile toujours pas meme en enlevant le pointeur et la fleche de la metode show()...

                toujours les 3 eme erreus...
                • Partager sur Facebook
                • Partager sur Twitter
                Anonyme
                  24 avril 2008 à 17:03:48

                  donne ton code
                  • Partager sur Facebook
                  • Partager sur Twitter
                    24 avril 2008 à 17:10:03

                    C'est un programme qui permet de controler le port parallele, mais c'est en portugais... puisque je suis au portugal... mais bon tu devrai t'y retrouver mais le code est grand..

                    Voici la bete:

                    main.cpp

                    #include <QApplication>
                    #include <QtGui>
                    #include "widget.h"
                    #include "janela2.h"
                    
                    int main(int argc, char *argv[])
                    {	
                    	QApplication app(argc, argv);
                        widget window;
                        window.show();
                        return app.exec();
                    }
                    


                    widget.cpp

                    #include <QtGui>
                    #include <windows.h>
                    #include <conio.h>
                    #include "widget.h"
                    #include "janela2.h"
                    
                    using namespace std;
                    
                    int repetition = 0;
                    byte statu_led = 0;
                    
                    typedef short _stdcall (*inpfuncPtr)(short portaddr);
                    typedef void _stdcall (*oupfuncPtr)(short portaddr, short datum);
                    
                    widget::widget(QWidget *parent) : QWidget(parent)
                    {
                    	setWindowTitle("Controlador de Led");
                    	ligar = new QPushButton("Ligar", this);
                    	desligar = new QPushButton("Desligar", this);
                    	slider = new QSlider(Qt::Horizontal);
                    	lcd = new QLCDNumber(1);
                    	check = new QCheckBox("Activar o Timing", this);
                    	chec1 = new QCheckBox("1", this);
                    	chec2 = new QCheckBox("2", this);
                    	chec3 = new QCheckBox("3", this);
                    	chec4 = new QCheckBox("4", this);
                    	chec5 = new QCheckBox("5", this);
                    	chec6 = new QCheckBox("6", this);
                    	chec7 = new QCheckBox("7", this);
                    	chec8 = new QCheckBox("8", this);
                    	check_statu = new QPushButton("Check State", this);
                    	
                    	timer = new QTimer(this);
                        
                    	
                    	lcd->setSegmentStyle(QLCDNumber::Filled);
                    	slider->setRange(0,8);
                    	slider->setValue(0);
                    	
                    	connect(slider, SIGNAL(valueChanged(int)), lcd, SLOT(display(int)));
                    	connect(ligar, SIGNAL(clicked()), this, SLOT(ligar_todos()));
                    	connect(desligar, SIGNAL(clicked()), this, SLOT(desligar_todos()));
                    	connect(slider, SIGNAL(valueChanged(int)), this, SLOT(ligar_led(int)));
                    	connect(timer, SIGNAL(timeout()), this, SLOT(timing()));
                    	connect(check, SIGNAL(stateChanged(int)), this, SLOT(update(int)));
                    	connect(chec1, SIGNAL(stateChanged(int)), this, SLOT(checkb1(int)));
                    	connect(chec2, SIGNAL(stateChanged(int)), this, SLOT(checkb2(int)));
                    	connect(chec3, SIGNAL(stateChanged(int)), this, SLOT(checkb3(int)));
                    	connect(chec4, SIGNAL(stateChanged(int)), this, SLOT(checkb4(int)));
                    	connect(chec5, SIGNAL(stateChanged(int)), this, SLOT(checkb5(int)));
                    	connect(chec6, SIGNAL(stateChanged(int)), this, SLOT(checkb6(int)));
                    	connect(chec7, SIGNAL(stateChanged(int)), this, SLOT(checkb7(int)));
                    	connect(chec8, SIGNAL(stateChanged(int)), this, SLOT(checkb8(int)));
                    	connect(check_statu, SIGNAL(clicked()), this, SLOT(check_state()));
                    	
                    	QHBoxLayout *check_layout = new QHBoxLayout();
                    	check_layout->addWidget(chec1);
                    	check_layout->addWidget(chec2);
                    	check_layout->addWidget(chec3);
                    	check_layout->addWidget(chec4);
                    	check_layout->addWidget(chec5);
                    	check_layout->addWidget(chec6);
                    	check_layout->addWidget(chec7);
                    	check_layout->addWidget(chec8);
                    	
                    	QHBoxLayout *button_layout = new QHBoxLayout();
                    	button_layout->addWidget(ligar);
                    	button_layout->addWidget(desligar);
                    	
                    	QVBoxLayout *main_layout = new QVBoxLayout();
                    	main_layout->addLayout(button_layout);
                    	main_layout->addLayout(check_layout);
                    	main_layout->addWidget(slider);
                    	main_layout->addWidget(lcd);
                    	main_layout->addWidget(check);
                    	main_layout->addWidget(check_statu);
                    	setLayout(main_layout);
                    }
                    
                    void widget::ligar_led (int num)
                    {
                    	HINSTANCE hLib;
                    	inpfuncPtr inp32;
                    	oupfuncPtr oup32;
                    	
                    	bool verif = true;
                    
                    	int Size = MultiByteToWideChar (CP_ACP, 0, "inpout32.dll", -1, NULL, 0);
                    	LPWSTR wUnicode = new WCHAR[Size];
                    	MultiByteToWideChar (CP_ACP, 0, "inpout32.dll", -1, wUnicode, Size);
                         
                         //Chargement de la librairie inpout32.dll
                        hLib = LoadLibrary(wUnicode);
                        if (hLib == NULL) {
                            QMessageBox::information(this, "Critical Error", "Impossivel de carregar a Inpout32.dll.");
                            verif = false;
                         }
                        inp32 = (inpfuncPtr) GetProcAddress(hLib, "Inp32");
                    
                         if (inp32 == NULL) {
                            QMessageBox::information(this, "Critical Error", "Processo Inp32 não funcionna correctamente.");
                    		verif = false;
                         }
                    
                         oup32 = (oupfuncPtr) GetProcAddress(hLib, "Out32");
                    
                         if (oup32 == NULL) {
                            QMessageBox::information(this, "Critical Error", "Processo Out32 não funcionna correctamente.");
                            verif = false;
                         }
                    	 
                    	if (verif)
                    	{
                    		if (num == 0)
                    		{
                    			oup32(0x378,0x0);
                    		}
                    		else if (num == 1)
                    		{
                    			oup32(0x378,0x1);
                    		}
                    		else if (num == 2)
                    		{
                    			oup32(0x378,0x2);
                    		}
                    		else if (num == 3)
                    		{
                    			oup32(0x378,0x4);
                    		}
                    		else if (num == 4)
                    		{
                    			oup32(0x378,0x8);
                    		}
                    		else if (num == 5)
                    		{
                    			oup32(0x378,0x10);
                    		}
                    		else if (num == 6)
                    		{
                    			oup32(0x378,0x20);
                    		}
                    		else if (num == 7)
                    		{
                    			oup32(0x378,0x40);
                    		}
                    		else if (num == 8)
                    		{
                    			oup32(0x378,0x80);
                    		}
                    	}
                    }
                    
                    
                    void widget::ligar_todos()
                    {
                    	HINSTANCE hLib;
                    	inpfuncPtr inp32;
                    	oupfuncPtr oup32;
                    	
                    	bool verif = true;
                    
                    	int Size = MultiByteToWideChar (CP_ACP, 0, "inpout32.dll", -1, NULL, 0);
                    	LPWSTR wUnicode = new WCHAR[Size];
                    	MultiByteToWideChar (CP_ACP, 0, "inpout32.dll", -1, wUnicode, Size);
                         
                         //Chargement de la librairie inpout32.dll
                        hLib = LoadLibrary(wUnicode);
                        if (hLib == NULL) {
                            QMessageBox::information(this, "Critical Error", "Impossivel de carregar a Inpout32.dll.");
                            verif = false;
                         }
                        inp32 = (inpfuncPtr) GetProcAddress(hLib, "Inp32");
                    
                         if (inp32 == NULL) {
                            QMessageBox::information(this, "Critical Error", "Processo Inp32 não funcionna correctamente.");
                    		verif = false;
                         }
                    
                         oup32 = (oupfuncPtr) GetProcAddress(hLib, "Out32");
                    
                         if (oup32 == NULL) {
                            QMessageBox::information(this, "Critical Error", "Processo Out32 não funcionna correctamente.");
                            verif = false;
                         }
                    	 
                    	 if (verif)
                    	 {
                    		chec1->setCheckState(Qt::Checked);
                    		chec2->setCheckState(Qt::Checked);
                    		chec3->setCheckState(Qt::Checked);
                    		chec4->setCheckState(Qt::Checked);
                    		chec5->setCheckState(Qt::Checked);
                    		chec6->setCheckState(Qt::Checked);
                    		chec7->setCheckState(Qt::Checked);
                    		chec8->setCheckState(Qt::Checked);
                    		oup32(0x378,0xFF);
                    	 }
                    }
                    
                    void widget::desligar_todos()
                    {
                    	HINSTANCE hLib;
                    	inpfuncPtr inp32;
                    	oupfuncPtr oup32;
                    	
                    	bool verif = true;
                    
                    	int Size = MultiByteToWideChar (CP_ACP, 0, "inpout32.dll", -1, NULL, 0);
                    	LPWSTR wUnicode = new WCHAR[Size];
                    	MultiByteToWideChar (CP_ACP, 0, "inpout32.dll", -1, wUnicode, Size);
                         
                         //Chargement de la librairie inpout32.dll
                        hLib = LoadLibrary(wUnicode);
                        if (hLib == NULL) {
                            QMessageBox::information(this, "Critical Error", "Impossivel de carregar a Inpout32.dll.");
                            verif = false;
                         }
                        inp32 = (inpfuncPtr) GetProcAddress(hLib, "Inp32");
                    
                         if (inp32 == NULL) {
                            QMessageBox::information(this, "Critical Error", "Processo Inp32 não funcionna correctamente.");
                    		verif = false;
                         }
                    
                         oup32 = (oupfuncPtr) GetProcAddress(hLib, "Out32");
                    
                         if (oup32 == NULL) {
                            QMessageBox::information(this, "Critical Error", "Processo Out32 não funcionna correctamente.");
                            verif = false;
                         }
                    	 
                    	if (verif)
                    	{
                    		chec1->setCheckState(Qt::Unchecked);
                    		chec2->setCheckState(Qt::Unchecked);
                    		chec3->setCheckState(Qt::Unchecked);
                    		chec4->setCheckState(Qt::Unchecked);
                    		chec5->setCheckState(Qt::Unchecked);
                    		chec6->setCheckState(Qt::Unchecked);
                    		chec7->setCheckState(Qt::Unchecked);
                    		chec8->setCheckState(Qt::Unchecked);
                    		oup32(0x378,0x0);
                    	}
                    }
                    
                    void widget::timing()
                    {
                    	HINSTANCE hLib;
                    	inpfuncPtr inp32;
                    	oupfuncPtr oup32;
                    	
                    	bool verif = true;
                    
                    	int Size = MultiByteToWideChar (CP_ACP, 0, "inpout32.dll", -1, NULL, 0);
                    	LPWSTR wUnicode = new WCHAR[Size];
                    	MultiByteToWideChar (CP_ACP, 0, "inpout32.dll", -1, wUnicode, Size);
                         
                         //Chargement de la librairie inpout32.dll
                        hLib = LoadLibrary(wUnicode);
                        if (hLib == NULL) {
                            QMessageBox::information(this, "Critical Error", "Impossivel de carregar a Inpout32.dll.");
                            verif = false;
                         }
                        inp32 = (inpfuncPtr) GetProcAddress(hLib, "Inp32");
                    
                         if (inp32 == NULL) {
                            QMessageBox::information(this, "Critical Error", "Processo Inp32 não funcionna correctamente.");
                    		verif = false;
                         }
                    
                         oup32 = (oupfuncPtr) GetProcAddress(hLib, "Out32");
                    
                         if (oup32 == NULL) {
                            QMessageBox::information(this, "Critical Error", "Processo Out32 não funcionna correctamente.");
                            verif = false;
                         }
                    	 
                    	if (verif)
                    	{
                    		if (repetition == 0)
                    		{
                    			oup32(0x378,0x1);
                    			repetition++;
                    		}
                    		else if (repetition == 1)
                    		{
                    			oup32(0x378,0x2);
                    			repetition++;
                    		}
                    		else if (repetition == 2)
                    		{
                    			oup32(0x378,0x4);
                    			repetition++;
                    		}
                    		else if (repetition == 3)
                    		{
                    			oup32(0x378,0x8);
                    			repetition++;
                    		}
                    		else if (repetition == 4)
                    		{
                    			oup32(0x378,0x10);
                    			repetition++;
                    		}
                    		else if (repetition == 5)
                    		{
                    			oup32(0x378,0x20);
                    			repetition++;
                    		}
                    		else if (repetition == 6)
                    		{
                    			oup32(0x378,0x40);
                    			repetition++;
                    		}
                    		else if (repetition == 7)
                    		{
                    			oup32(0x378,0x80);
                    			repetition++;
                    		}
                    		else if (repetition == 8)
                    		{
                    			oup32(0x378,0x40);
                    			repetition++;
                    		}
                    		else if (repetition == 9)
                    		{
                    			oup32(0x378,0x20);
                    			repetition++;
                    		}
                    		else if (repetition == 10)
                    		{
                    			oup32(0x378,0x10);
                    			repetition++;
                    		}
                    		else if (repetition == 11)
                    		{
                    			oup32(0x378,0x8);
                    			repetition++;
                    		}
                    		else if (repetition == 12)
                    		{
                    			oup32(0x378,0x4);
                    			repetition++;
                    		}
                    		else if (repetition == 13)
                    		{
                    			oup32(0x378,0x2);
                    			repetition++;
                    		}
                    		else if (repetition == 14)
                    		{
                    			oup32(0x378,0x1);
                    			repetition++;
                    		}
                    		else if (repetition == 15)
                    		{
                    			repetition = 0;
                    		}
                    	}
                    }
                    
                    void widget::update(int num)
                    {
                    	if (check->isChecked())
                    	{
                    		timer->start(20);
                    		ligar->setDisabled(true);
                    		desligar->setDisabled(true);
                    	}
                    	else
                    	{
                    		timer->stop();
                    		ligar->setDisabled(false);
                    		desligar->setDisabled(false);
                    	}
                    }
                    
                    void widget::checkb1(int num)
                    {
                    	if(chec1->isChecked())
                    	{
                    		statu_led += 1;
                    	}
                    	else
                    	{
                    		statu_led -= 1;
                    	}
                    	
                    	check_initialization();
                    }
                    
                    void widget::checkb2(int num)
                    {
                    	if(chec2->isChecked())
                    	{
                    		statu_led += 2;
                    	}
                    	else
                    	{
                    		statu_led -= 2;
                    	}
                    	
                    	check_initialization();
                    }
                    
                    void widget::checkb3(int num)
                    {
                    	if(chec3->isChecked())
                    	{
                    		statu_led += 4;
                    	}
                    	else
                    	{
                    		statu_led -= 4;
                    	}
                    	
                    	check_initialization();
                    }
                    
                    void widget::checkb4(int num)
                    {
                    	if(chec4->isChecked())
                    	{
                    		statu_led += 8;
                    	}
                    	else
                    	{
                    		statu_led -= 8;
                    	}
                    	
                    	check_initialization();
                    }
                    
                    void widget::checkb5(int num)
                    {
                    	if(chec5->isChecked())
                    	{
                    		statu_led += 16;
                    	}
                    	else
                    	{
                    		statu_led -= 16;
                    	}
                    	
                    	check_initialization();
                    }
                    
                    void widget::checkb6(int num)
                    {
                    	if(chec6->isChecked())
                    	{
                    		statu_led += 32;
                    	}
                    	else
                    	{
                    		statu_led -= 32;
                    	}
                    	
                    	check_initialization();
                    }
                    
                    void widget::checkb7(int num)
                    {
                    	if(chec7->isChecked())
                    	{
                    		statu_led += 64;
                    	}
                    	else
                    	{
                    		statu_led -= 64;
                    	}
                    	
                    	check_initialization();
                    }
                    
                    void widget::checkb8(int num)
                    {
                    	if(chec8->isChecked())
                    	{
                    		statu_led += 128;
                    	}
                    	else
                    	{
                    		statu_led -= 128;
                    	}
                    	
                    	check_initialization();
                    }
                    
                    void widget::check_initialization ()
                    {
                    	HINSTANCE hLib;
                    	inpfuncPtr inp32;
                    	oupfuncPtr oup32;
                    	
                    	bool verif = true;
                    
                    	int Size = MultiByteToWideChar (CP_ACP, 0, "inpout32.dll", -1, NULL, 0);
                    	LPWSTR wUnicode = new WCHAR[Size];
                    	MultiByteToWideChar (CP_ACP, 0, "inpout32.dll", -1, wUnicode, Size);
                         
                         //Chargement de la librairie inpout32.dll
                        hLib = LoadLibrary(wUnicode);
                        if (hLib == NULL) {
                            QMessageBox::information(this, "Critical Error", "Impossivel de carregar a Inpout32.dll.");
                            verif = false;
                         }
                        inp32 = (inpfuncPtr) GetProcAddress(hLib, "Inp32");
                    
                         if (inp32 == NULL) {
                            QMessageBox::information(this, "Critical Error", "Processo Inp32 não funcionna correctamente.");
                    		verif = false;
                         }
                    
                         oup32 = (oupfuncPtr) GetProcAddress(hLib, "Out32");
                    
                         if (oup32 == NULL) {
                            QMessageBox::information(this, "Critical Error", "Processo Out32 não funcionna correctamente.");
                            verif = false;
                         }
                    	 
                    	 if (verif)
                    	 {
                    		oup32(0x378,statu_led);
                    	 }
                    }
                    
                    void widget::check_state()
                    {
                    	window2.show();
                    }
                    


                    widget.h

                    #include <QtGui>
                    #include "janela2.h"
                    
                    class widget : public QWidget
                    {
                    	Q_OBJECT
                    
                       public:
                    	widget(QWidget *parent = 0);
                    
                       public slots:
                    	void ligar_led (int num);
                    	void ligar_todos();
                    	void desligar_todos();
                    	void timing();
                    	void update(int num);
                    	void checkb1(int num);
                    	void checkb2(int num);
                    	void checkb3(int num);
                    	void checkb4(int num);
                    	void checkb5(int num);
                    	void checkb6(int num);
                    	void checkb7(int num);
                    	void checkb8(int num);
                    	void check_initialization();
                    	void check_state();
                    	
                       private:
                        QPushButton *ligar;
                    	QPushButton *desligar;
                    	QSlider *slider;
                    	QLCDNumber *lcd;
                    	QTimer *timer;
                    	QCheckBox *check;
                    	QPushButton *check_statu;
                    	
                    	QCheckBox *chec1;
                    	QCheckBox *chec2;
                    	QCheckBox *chec3;
                    	QCheckBox *chec4;
                    	QCheckBox *chec5;
                    	QCheckBox *chec6;
                    	QCheckBox *chec7;
                    	QCheckBox *chec8;
                    	
                    	janela window2;
                    };
                    


                    janela.cpp (sa veut dire fenetre en français)

                    #include <QtGui>
                    #include <windows.h>
                    #include <conio.h>
                    #include "widget.h"
                    #include "janela2.h"
                    
                    using namespace std;
                    
                    typedef short _stdcall (*inpfuncPtr)(short portaddr);
                    typedef void _stdcall (*oupfuncPtr)(short portaddr, short datum);
                    
                    janela::janela(QWidget *parent) : QWidget(parent)
                    {
                    	led1 = new QLabel("Led 1:", this);
                    	led2 = new QLabel("Led 2:", this);
                    	led3 = new QLabel("Led 3:", this);
                    	led4 = new QLabel("Led 4:", this);
                    	led5 = new QLabel("Led 5:", this);
                    	led6 = new QLabel("Led 6:", this);
                    	led7 = new QLabel("Led 7:", this);
                    	led8 = new QLabel("Led 8:", this);
                    	
                    	QVBoxLayout *main_layout = new QVBoxLayout();
                    	main_layout->addWidget(led1);
                    	main_layout->addWidget(led2);
                    	main_layout->addWidget(led3);
                    	main_layout->addWidget(led4);
                    	main_layout->addWidget(led5);
                    	main_layout->addWidget(led6);
                    	main_layout->addWidget(led7);
                    	main_layout->addWidget(led8);
                    	setLayout(main_layout);
                    }
                    


                    janela.h

                    #include <QtGui>
                    
                    class janela : public QWidget
                    {
                    	Q_OBJECT
                    
                    	public:
                    		janela(QWidget *parent = 0);
                    		
                    	private:
                    		QLabel *led1;
                    		QLabel *led2;
                    		QLabel *led3;
                    		QLabel *led4;
                    		QLabel *led5;
                    		QLabel *led6;
                    		QLabel *led7;
                    		QLabel *led8;
                    };
                    


                    Merci d'avance si tu peut me resoudre sa.
                    • Partager sur Facebook
                    • Partager sur Twitter
                    Anonyme
                      24 avril 2008 à 17:21:15

                      met des securité anti multi inclusion
                      #ifndef DEF_NomDuFichier
                      #define DEF_NomDuFichier
                      
                      //ton code la
                      
                      #endif
                      
                      • Partager sur Facebook
                      • Partager sur Twitter
                      Anonyme
                        24 avril 2008 à 17:30:01

                        je crois, je suis en train de tester.
                        ps: les directive, on ne les met que pour les .h

                        EDIT: il est ou le fichier janela.h ?

                        EDIT: voici le code qui marche (pour janela2.h j'ai considéré que c'etait janela.h)

                        main.cpp
                        #include <QApplication>
                        #include <QtGui>
                        #include "widget.h"
                        #include "janela.h"
                        
                        int main(int argc, char *argv[])
                        {	
                        	QApplication app(argc, argv);
                            widget window;
                            window.show();
                            return app.exec();
                        }
                        


                        widget.cpp
                        #include <QtGui>
                        #include <windows.h>
                        #include <conio.h>
                        #include "widget.h"
                        #include "janela.h"
                        
                        using namespace std;
                        
                        int repetition = 0;
                        byte statu_led = 0;
                        
                        typedef short _stdcall (*inpfuncPtr)(short portaddr);
                        typedef void _stdcall (*oupfuncPtr)(short portaddr, short datum);
                        
                        widget::widget(QWidget *parent) : QWidget(parent)
                        {
                        	setWindowTitle("Controlador de Led");
                        	ligar = new QPushButton("Ligar", this);
                        	desligar = new QPushButton("Desligar", this);
                        	slider = new QSlider(Qt::Horizontal);
                        	lcd = new QLCDNumber(1);
                        	check = new QCheckBox("Activar o Timing", this);
                        	chec1 = new QCheckBox("1", this);
                        	chec2 = new QCheckBox("2", this);
                        	chec3 = new QCheckBox("3", this);
                        	chec4 = new QCheckBox("4", this);
                        	chec5 = new QCheckBox("5", this);
                        	chec6 = new QCheckBox("6", this);
                        	chec7 = new QCheckBox("7", this);
                        	chec8 = new QCheckBox("8", this);
                        	check_statu = new QPushButton("Check State", this);
                        	
                        	timer = new QTimer(this);
                            
                        	
                        	lcd->setSegmentStyle(QLCDNumber::Filled);
                        	slider->setRange(0,8);
                        	slider->setValue(0);
                        	
                        	connect(slider, SIGNAL(valueChanged(int)), lcd, SLOT(display(int)));
                        	connect(ligar, SIGNAL(clicked()), this, SLOT(ligar_todos()));
                        	connect(desligar, SIGNAL(clicked()), this, SLOT(desligar_todos()));
                        	connect(slider, SIGNAL(valueChanged(int)), this, SLOT(ligar_led(int)));
                        	connect(timer, SIGNAL(timeout()), this, SLOT(timing()));
                        	connect(check, SIGNAL(stateChanged(int)), this, SLOT(update(int)));
                        	connect(chec1, SIGNAL(stateChanged(int)), this, SLOT(checkb1(int)));
                        	connect(chec2, SIGNAL(stateChanged(int)), this, SLOT(checkb2(int)));
                        	connect(chec3, SIGNAL(stateChanged(int)), this, SLOT(checkb3(int)));
                        	connect(chec4, SIGNAL(stateChanged(int)), this, SLOT(checkb4(int)));
                        	connect(chec5, SIGNAL(stateChanged(int)), this, SLOT(checkb5(int)));
                        	connect(chec6, SIGNAL(stateChanged(int)), this, SLOT(checkb6(int)));
                        	connect(chec7, SIGNAL(stateChanged(int)), this, SLOT(checkb7(int)));
                        	connect(chec8, SIGNAL(stateChanged(int)), this, SLOT(checkb8(int)));
                        	connect(check_statu, SIGNAL(clicked()), this, SLOT(check_state()));
                        	
                        	QHBoxLayout *check_layout = new QHBoxLayout();
                        	check_layout->addWidget(chec1);
                        	check_layout->addWidget(chec2);
                        	check_layout->addWidget(chec3);
                        	check_layout->addWidget(chec4);
                        	check_layout->addWidget(chec5);
                        	check_layout->addWidget(chec6);
                        	check_layout->addWidget(chec7);
                        	check_layout->addWidget(chec8);
                        	
                        	QHBoxLayout *button_layout = new QHBoxLayout();
                        	button_layout->addWidget(ligar);
                        	button_layout->addWidget(desligar);
                        	
                        	QVBoxLayout *main_layout = new QVBoxLayout();
                        	main_layout->addLayout(button_layout);
                        	main_layout->addLayout(check_layout);
                        	main_layout->addWidget(slider);
                        	main_layout->addWidget(lcd);
                        	main_layout->addWidget(check);
                        	main_layout->addWidget(check_statu);
                        	setLayout(main_layout);
                        }
                        
                        void widget::ligar_led (int num)
                        {
                        	HINSTANCE hLib;
                        	inpfuncPtr inp32;
                        	oupfuncPtr oup32;
                        	
                        	bool verif = true;
                        
                        	int Size = MultiByteToWideChar (CP_ACP, 0, "inpout32.dll", -1, NULL, 0);
                        	LPWSTR wUnicode = new WCHAR[Size];
                        	MultiByteToWideChar (CP_ACP, 0, "inpout32.dll", -1, wUnicode, Size);
                             
                             //Chargement de la librairie inpout32.dll
                            hLib = LoadLibrary(wUnicode);
                            if (hLib == NULL) {
                                QMessageBox::information(this, "Critical Error", "Impossivel de carregar a Inpout32.dll.");
                                verif = false;
                             }
                            inp32 = (inpfuncPtr) GetProcAddress(hLib, "Inp32");
                        
                             if (inp32 == NULL) {
                                QMessageBox::information(this, "Critical Error", "Processo Inp32 não funcionna correctamente.");
                        		verif = false;
                             }
                        
                             oup32 = (oupfuncPtr) GetProcAddress(hLib, "Out32");
                        
                             if (oup32 == NULL) {
                                QMessageBox::information(this, "Critical Error", "Processo Out32 não funcionna correctamente.");
                                verif = false;
                             }
                        	 
                        	if (verif)
                        	{
                        		if (num == 0)
                        		{
                        			oup32(0x378,0x0);
                        		}
                        		else if (num == 1)
                        		{
                        			oup32(0x378,0x1);
                        		}
                        		else if (num == 2)
                        		{
                        			oup32(0x378,0x2);
                        		}
                        		else if (num == 3)
                        		{
                        			oup32(0x378,0x4);
                        		}
                        		else if (num == 4)
                        		{
                        			oup32(0x378,0x8);
                        		}
                        		else if (num == 5)
                        		{
                        			oup32(0x378,0x10);
                        		}
                        		else if (num == 6)
                        		{
                        			oup32(0x378,0x20);
                        		}
                        		else if (num == 7)
                        		{
                        			oup32(0x378,0x40);
                        		}
                        		else if (num == 8)
                        		{
                        			oup32(0x378,0x80);
                        		}
                        	}
                        }
                        
                        
                        void widget::ligar_todos()
                        {
                        	HINSTANCE hLib;
                        	inpfuncPtr inp32;
                        	oupfuncPtr oup32;
                        	
                        	bool verif = true;
                        
                        	int Size = MultiByteToWideChar (CP_ACP, 0, "inpout32.dll", -1, NULL, 0);
                        	LPWSTR wUnicode = new WCHAR[Size];
                        	MultiByteToWideChar (CP_ACP, 0, "inpout32.dll", -1, wUnicode, Size);
                             
                             //Chargement de la librairie inpout32.dll
                            hLib = LoadLibrary(wUnicode);
                            if (hLib == NULL) {
                                QMessageBox::information(this, "Critical Error", "Impossivel de carregar a Inpout32.dll.");
                                verif = false;
                             }
                            inp32 = (inpfuncPtr) GetProcAddress(hLib, "Inp32");
                        
                             if (inp32 == NULL) {
                                QMessageBox::information(this, "Critical Error", "Processo Inp32 não funcionna correctamente.");
                        		verif = false;
                             }
                        
                             oup32 = (oupfuncPtr) GetProcAddress(hLib, "Out32");
                        
                             if (oup32 == NULL) {
                                QMessageBox::information(this, "Critical Error", "Processo Out32 não funcionna correctamente.");
                                verif = false;
                             }
                        	 
                        	 if (verif)
                        	 {
                        		chec1->setCheckState(Qt::Checked);
                        		chec2->setCheckState(Qt::Checked);
                        		chec3->setCheckState(Qt::Checked);
                        		chec4->setCheckState(Qt::Checked);
                        		chec5->setCheckState(Qt::Checked);
                        		chec6->setCheckState(Qt::Checked);
                        		chec7->setCheckState(Qt::Checked);
                        		chec8->setCheckState(Qt::Checked);
                        		oup32(0x378,0xFF);
                        	 }
                        }
                        
                        void widget::desligar_todos()
                        {
                        	HINSTANCE hLib;
                        	inpfuncPtr inp32;
                        	oupfuncPtr oup32;
                        	
                        	bool verif = true;
                        
                        	int Size = MultiByteToWideChar (CP_ACP, 0, "inpout32.dll", -1, NULL, 0);
                        	LPWSTR wUnicode = new WCHAR[Size];
                        	MultiByteToWideChar (CP_ACP, 0, "inpout32.dll", -1, wUnicode, Size);
                             
                             //Chargement de la librairie inpout32.dll
                            hLib = LoadLibrary(wUnicode);
                            if (hLib == NULL) {
                                QMessageBox::information(this, "Critical Error", "Impossivel de carregar a Inpout32.dll.");
                                verif = false;
                             }
                            inp32 = (inpfuncPtr) GetProcAddress(hLib, "Inp32");
                        
                             if (inp32 == NULL) {
                                QMessageBox::information(this, "Critical Error", "Processo Inp32 não funcionna correctamente.");
                        		verif = false;
                             }
                        
                             oup32 = (oupfuncPtr) GetProcAddress(hLib, "Out32");
                        
                             if (oup32 == NULL) {
                                QMessageBox::information(this, "Critical Error", "Processo Out32 não funcionna correctamente.");
                                verif = false;
                             }
                        	 
                        	if (verif)
                        	{
                        		chec1->setCheckState(Qt::Unchecked);
                        		chec2->setCheckState(Qt::Unchecked);
                        		chec3->setCheckState(Qt::Unchecked);
                        		chec4->setCheckState(Qt::Unchecked);
                        		chec5->setCheckState(Qt::Unchecked);
                        		chec6->setCheckState(Qt::Unchecked);
                        		chec7->setCheckState(Qt::Unchecked);
                        		chec8->setCheckState(Qt::Unchecked);
                        		oup32(0x378,0x0);
                        	}
                        }
                        
                        void widget::timing()
                        {
                        	HINSTANCE hLib;
                        	inpfuncPtr inp32;
                        	oupfuncPtr oup32;
                        	
                        	bool verif = true;
                        
                        	int Size = MultiByteToWideChar (CP_ACP, 0, "inpout32.dll", -1, NULL, 0);
                        	LPWSTR wUnicode = new WCHAR[Size];
                        	MultiByteToWideChar (CP_ACP, 0, "inpout32.dll", -1, wUnicode, Size);
                             
                             //Chargement de la librairie inpout32.dll
                            hLib = LoadLibrary(wUnicode);
                            if (hLib == NULL) {
                                QMessageBox::information(this, "Critical Error", "Impossivel de carregar a Inpout32.dll.");
                                verif = false;
                             }
                            inp32 = (inpfuncPtr) GetProcAddress(hLib, "Inp32");
                        
                             if (inp32 == NULL) {
                                QMessageBox::information(this, "Critical Error", "Processo Inp32 não funcionna correctamente.");
                        		verif = false;
                             }
                        
                             oup32 = (oupfuncPtr) GetProcAddress(hLib, "Out32");
                        
                             if (oup32 == NULL) {
                                QMessageBox::information(this, "Critical Error", "Processo Out32 não funcionna correctamente.");
                                verif = false;
                             }
                        	 
                        	if (verif)
                        	{
                        		if (repetition == 0)
                        		{
                        			oup32(0x378,0x1);
                        			repetition++;
                        		}
                        		else if (repetition == 1)
                        		{
                        			oup32(0x378,0x2);
                        			repetition++;
                        		}
                        		else if (repetition == 2)
                        		{
                        			oup32(0x378,0x4);
                        			repetition++;
                        		}
                        		else if (repetition == 3)
                        		{
                        			oup32(0x378,0x8);
                        			repetition++;
                        		}
                        		else if (repetition == 4)
                        		{
                        			oup32(0x378,0x10);
                        			repetition++;
                        		}
                        		else if (repetition == 5)
                        		{
                        			oup32(0x378,0x20);
                        			repetition++;
                        		}
                        		else if (repetition == 6)
                        		{
                        			oup32(0x378,0x40);
                        			repetition++;
                        		}
                        		else if (repetition == 7)
                        		{
                        			oup32(0x378,0x80);
                        			repetition++;
                        		}
                        		else if (repetition == 8)
                        		{
                        			oup32(0x378,0x40);
                        			repetition++;
                        		}
                        		else if (repetition == 9)
                        		{
                        			oup32(0x378,0x20);
                        			repetition++;
                        		}
                        		else if (repetition == 10)
                        		{
                        			oup32(0x378,0x10);
                        			repetition++;
                        		}
                        		else if (repetition == 11)
                        		{
                        			oup32(0x378,0x8);
                        			repetition++;
                        		}
                        		else if (repetition == 12)
                        		{
                        			oup32(0x378,0x4);
                        			repetition++;
                        		}
                        		else if (repetition == 13)
                        		{
                        			oup32(0x378,0x2);
                        			repetition++;
                        		}
                        		else if (repetition == 14)
                        		{
                        			oup32(0x378,0x1);
                        			repetition++;
                        		}
                        		else if (repetition == 15)
                        		{
                        			repetition = 0;
                        		}
                        	}
                        }
                        
                        void widget::update(int num)
                        {
                        	if (check->isChecked())
                        	{
                        		timer->start(20);
                        		ligar->setDisabled(true);
                        		desligar->setDisabled(true);
                        	}
                        	else
                        	{
                        		timer->stop();
                        		ligar->setDisabled(false);
                        		desligar->setDisabled(false);
                        	}
                        }
                        
                        void widget::checkb1(int num)
                        {
                        	if(chec1->isChecked())
                        	{
                        		statu_led += 1;
                        	}
                        	else
                        	{
                        		statu_led -= 1;
                        	}
                        	
                        	check_initialization();
                        }
                        
                        void widget::checkb2(int num)
                        {
                        	if(chec2->isChecked())
                        	{
                        		statu_led += 2;
                        	}
                        	else
                        	{
                        		statu_led -= 2;
                        	}
                        	
                        	check_initialization();
                        }
                        
                        void widget::checkb3(int num)
                        {
                        	if(chec3->isChecked())
                        	{
                        		statu_led += 4;
                        	}
                        	else
                        	{
                        		statu_led -= 4;
                        	}
                        	
                        	check_initialization();
                        }
                        
                        void widget::checkb4(int num)
                        {
                        	if(chec4->isChecked())
                        	{
                        		statu_led += 8;
                        	}
                        	else
                        	{
                        		statu_led -= 8;
                        	}
                        	
                        	check_initialization();
                        }
                        
                        void widget::checkb5(int num)
                        {
                        	if(chec5->isChecked())
                        	{
                        		statu_led += 16;
                        	}
                        	else
                        	{
                        		statu_led -= 16;
                        	}
                        	
                        	check_initialization();
                        }
                        
                        void widget::checkb6(int num)
                        {
                        	if(chec6->isChecked())
                        	{
                        		statu_led += 32;
                        	}
                        	else
                        	{
                        		statu_led -= 32;
                        	}
                        	
                        	check_initialization();
                        }
                        
                        void widget::checkb7(int num)
                        {
                        	if(chec7->isChecked())
                        	{
                        		statu_led += 64;
                        	}
                        	else
                        	{
                        		statu_led -= 64;
                        	}
                        	
                        	check_initialization();
                        }
                        
                        void widget::checkb8(int num)
                        {
                        	if(chec8->isChecked())
                        	{
                        		statu_led += 128;
                        	}
                        	else
                        	{
                        		statu_led -= 128;
                        	}
                        	
                        	check_initialization();
                        }
                        
                        void widget::check_initialization ()
                        {
                        	HINSTANCE hLib;
                        	inpfuncPtr inp32;
                        	oupfuncPtr oup32;
                        	
                        	bool verif = true;
                        
                        	int Size = MultiByteToWideChar (CP_ACP, 0, "inpout32.dll", -1, NULL, 0);
                        	LPWSTR wUnicode = new WCHAR[Size];
                        	MultiByteToWideChar (CP_ACP, 0, "inpout32.dll", -1, wUnicode, Size);
                             
                             //Chargement de la librairie inpout32.dll
                            hLib = LoadLibrary(wUnicode);
                            if (hLib == NULL) {
                                QMessageBox::information(this, "Critical Error", "Impossivel de carregar a Inpout32.dll.");
                                verif = false;
                             }
                            inp32 = (inpfuncPtr) GetProcAddress(hLib, "Inp32");
                        
                             if (inp32 == NULL) {
                                QMessageBox::information(this, "Critical Error", "Processo Inp32 não funcionna correctamente.");
                        		verif = false;
                             }
                        
                             oup32 = (oupfuncPtr) GetProcAddress(hLib, "Out32");
                        
                             if (oup32 == NULL) {
                                QMessageBox::information(this, "Critical Error", "Processo Out32 não funcionna correctamente.");
                                verif = false;
                             }
                        	 
                        	 if (verif)
                        	 {
                        		oup32(0x378,statu_led);
                        	 }
                        }
                        
                        void widget::check_state()
                        {
                        	window2.show();
                        }
                        

                        widget.h
                        #ifndef DEF_widget
                        #define DEF_widget
                        
                        #include <QtGui>
                        #include "janela.h"
                        
                        class widget : public QWidget
                        {
                        	Q_OBJECT
                        
                           public:
                        	widget(QWidget *parent = 0);
                        
                           public slots:
                        	void ligar_led (int num);
                        	void ligar_todos();
                        	void desligar_todos();
                        	void timing();
                        	void update(int num);
                        	void checkb1(int num);
                        	void checkb2(int num);
                        	void checkb3(int num);
                        	void checkb4(int num);
                        	void checkb5(int num);
                        	void checkb6(int num);
                        	void checkb7(int num);
                        	void checkb8(int num);
                        	void check_initialization();
                        	void check_state();
                        	
                           private:
                            QPushButton *ligar;
                        	QPushButton *desligar;
                        	QSlider *slider;
                        	QLCDNumber *lcd;
                        	QTimer *timer;
                        	QCheckBox *check;
                        	QPushButton *check_statu;
                        	
                        	QCheckBox *chec1;
                        	QCheckBox *chec2;
                        	QCheckBox *chec3;
                        	QCheckBox *chec4;
                        	QCheckBox *chec5;
                        	QCheckBox *chec6;
                        	QCheckBox *chec7;
                        	QCheckBox *chec8;
                        	
                        	janela window2;
                        };
                        
                        #endif
                        

                        janela.cpp
                        #include <QtGui>
                        #include <windows.h>
                        #include <conio.h>
                        #include "widget.h"
                        #include "janela.h"
                        
                        using namespace std;
                        
                        typedef short _stdcall (*inpfuncPtr)(short portaddr);
                        typedef void _stdcall (*oupfuncPtr)(short portaddr, short datum);
                        
                        janela::janela(QWidget *parent) : QWidget(parent)
                        {
                        	led1 = new QLabel("Led 1:", this);
                        	led2 = new QLabel("Led 2:", this);
                        	led3 = new QLabel("Led 3:", this);
                        	led4 = new QLabel("Led 4:", this);
                        	led5 = new QLabel("Led 5:", this);
                        	led6 = new QLabel("Led 6:", this);
                        	led7 = new QLabel("Led 7:", this);
                        	led8 = new QLabel("Led 8:", this);
                        	
                        	QVBoxLayout *main_layout = new QVBoxLayout();
                        	main_layout->addWidget(led1);
                        	main_layout->addWidget(led2);
                        	main_layout->addWidget(led3);
                        	main_layout->addWidget(led4);
                        	main_layout->addWidget(led5);
                        	main_layout->addWidget(led6);
                        	main_layout->addWidget(led7);
                        	main_layout->addWidget(led8);
                        	setLayout(main_layout);
                        }
                        

                        janela.h
                        #ifndef DEF_janela
                        #define DEF_janela
                        
                        #include <QtGui>
                        
                        class janela : public QWidget
                        {
                        	Q_OBJECT
                        
                        	public:
                        		janela(QWidget *parent = 0);
                        		
                        	private:
                        		QLabel *led1;
                        		QLabel *led2;
                        		QLabel *led3;
                        		QLabel *led4;
                        		QLabel *led5;
                        		QLabel *led6;
                        		QLabel *led7;
                        		QLabel *led8;
                        };
                        
                        #endif
                        
                        • Partager sur Facebook
                        • Partager sur Twitter
                          24 avril 2008 à 17:52:27

                          ba il est avec les autre... mais je vien de te donner son code source.

                          EDIT: Sa marche ! sa marche!!

                          mais un dernier truc quand j'ouvre la deuxieme fenetre il m'apparait dans la barre des tache l'autre fenetre, et je peut meme la minimizer... moi je voudrai qu'il n'apparaisse qu'une seule et unique aplication et que quand je ferme la premiere fenetre qui est la fenetre mere, l'autre se ferme aussi.

                          merci si tu pourrai me faire les modification necessaire ou me mettre sur une piste.
                          • Partager sur Facebook
                          • Partager sur Twitter
                          Anonyme
                            24 avril 2008 à 17:59:10

                            je voulais dire ou est janela2.h (tu a fais une erreur dans les #include)
                            sinon la liste de if... else if ... else if... m'as choquer: il aurait falut utiliser un switch
                            • Partager sur Facebook
                            • Partager sur Twitter
                              24 avril 2008 à 18:01:08

                              dsl... j'y avait plus pensait... mais bon sa marche et avec les copain plus y a de ligne plus on impressionne!!

                              loooool
                              • Partager sur Facebook
                              • Partager sur Twitter
                              Anonyme
                                24 avril 2008 à 18:05:43

                                si ca marche met resolut
                                • Partager sur Facebook
                                • Partager sur Twitter
                                  24 avril 2008 à 18:06:57

                                  oki et vraiment merci pour tout.

                                  EDIT un dernier probleme, quand j'ouvre ma seconde fenetre elle me la met dans la barre des tache en bas pres du bouton Demarer et je peut meme la minimizer...
                                  Je voudrai avoir une seule et unique application mais avec plusieur fenetre qui n'apparaisse pas dans la barre des tache. de plus si c'est possible que quand on ferme la fenetre mere qui est la premiere fenetre toute les autres se ferme aussi.

                                  pouvez vous m'aider?

                                  merci d'avance
                                  • Partager sur Facebook
                                  • Partager sur Twitter
                                    5 mai 2008 à 19:54:05

                                    oki doki.... but thanks for the help guys!!...
                                    • Partager sur Facebook
                                    • Partager sur Twitter

                                    [Qt] ouvertture d'une fenetre

                                    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
                                    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
                                    • Editeur
                                    • Markdown