| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 1 | |
Hi! I am new to Qt. Can you get me up to speed on this. What seems
to be wrong with my code. I want to spawn an MS DOS window when a user
clicks the "DOS" button. My code are as follows:
#include <cstdlib>
#include <QObject>
#include <QApplication>
#include <QPushButton>
#include <QProcess>
#include <QStringList>
#include <QHBoxLayout>
int main( int argc, char *argv[] )
{
QApplication app(argc, argv);
QWidget * window = new QWidget;
window->setWindowTitle("SMIS");
QPushButton * button1 = new QPushButton("Dos");
QPushButton * button2 = new QPushButton("Quit");
QObject::connect(button1, SIGNAL(clicked()),
&app, SLOT( system("cmd.exe") ));
QObject::connect(button2, SIGNAL(clicked()),
&app, SLOT( quit() ));
QHBoxLayout * layout = new QHBoxLayout;
layout->addWidget(button1);
layout->addWidget(button2);
window->setLayout(layout);
window->show();
return app.exec();
}
Quit() seems to work. But the system() does not. Am I missing
something. I've read through QProcess but the actual execution seems to escape
me.
Clem
Clement L. Rasul
e-mail: clemrasul@xxxxxxxxx
---------------------------------
Never miss a thing. Make Yahoo your homepage.
The arguments in the SIGNAL() and SLOT() parameters must match. The
clicked() signal sends no parameters, and system(const char*) is not a slot
for QApplication and it requires a parameter.
You need to create an object with a slot that calls
system(getenv("comspec")). (Not cmd.exe!)
class cmdCall : public QProcess
{
...
public slot:
void cmdexe() { execute(getenv("comspec")); };
...
}
Then in your code:
...
cmdCall sys;
...
QObject::connect(button1, SIGNAL(clicked()), &sys, SLOT(cmdexe()));
Keith
**Please do not reply to me, reply to the list.**
On 01-04-2008 6:24 PM, "Clement L. Rasul" wrote:
> Hi! I am new to Qt. Can you get me up to speed on this. What seems
> to be wrong with my code. I want to spawn an MS DOS window when a user
> clicks the "DOS" button. My code are as follows:
>
> #include <cstdlib>
> #include <QObject>
> #include <QApplication>
> #include <QPushButton>
> #include <QProcess>
> #include <QStringList>
> #include <QHBoxLayout>
>
> int main( int argc, char *argv[] )
> {
> QApplication app(argc, argv);
>
> QWidget * window = new QWidget;
> window->setWindowTitle("SMIS");
>
> QPushButton * button1 = new QPushButton("Dos");
> QPushButton * button2 = new QPushButton("Quit");
>
> QObject::connect(button1, SIGNAL(clicked()),
> &app, SLOT( system("cmd.exe") ));
>
> QObject::connect(button2, SIGNAL(clicked()),
> &app, SLOT( quit() ));
>
> QHBoxLayout * layout = new
> QHBoxLayout;
> layout->addWidget(button1);
> layout->addWidget(button2);
> window->setLayout(layout);
>
> window->show();
>
> return app.exec();
>
> }
>
>
> Quit() seems to work. But the system() does not. Am I missing
> something. I've read through QProcess but the actual execution seems to
> escape
> me.
>
> Clem
>
>
> Clement L. Rasul
> e-mail: clemrasul@xxxxxxxxx
If I understood you right, the code should be this way:
include <iostream>
#include <QObject>
#include <QApplication>
#include <QPushButton>
#include <QProcess>
#include <QHBoxLayout>
class cmdCall : public QProcess
{
Q_OBJECT
public slots:
void cmdexe() { execute(getenv("comspec")); };
};
int main( int argc, char *argv[])
{
QApplication app( argc, argv );
cmdCall sys;
QWidget * window = new QWidget;
window->setWindowTitle("SMIS");
QPushButton * button1 = new QPushButton("Dos");
QPushButton * button2 = new QPushButton("Quit");
QObject::connect(button1, SIGNAL(clicked()), &sys, SLOT(cmdexe()));
QObject::connect(button2, SIGNAL(clicked()), &app, SLOT( quit() ));
QHBoxLayout * layout = new QHBoxLayout;
layout->addWidget(button1);
layout->addWidget(button2);
window->setLayout(layout);
window->show();
return app.exec();
}
This one will not compile. I understand that I need to put the Q_OBJECT in the class cmdCall. The compiler message are as follows:
C:\Qt\4.1.1\clem>MAKE
mingw32-make -f Makefile.Debug all
mingw32-make[1]: Entering directory `C:/Qt/4.1.1/clem'
g++ -c -g -g -frtti -fexceptions -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"C:/Qt/4.1.1/include/QtCore" -I"C:/Qt/4.1.1
/include/QtGui" -I"C:/Qt/4.1.1/include" -I"." -I"C:/Qt/4.1.1/include/ActiveQt" -I"tmp\moc\debug_shared" -I"." -I"C:/Qt/4.1.1/mkspecs/win32-g++" -o tmp\obj\debug_shared\clem.o clem.cpp
clem.cpp:37:2: warning: no newline at end of file
g++ -mthreads -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-subsystem,windows -o "debug\clem.exe" tmp\obj\debug_shared\clem.o -L"C:\Qt\4.1.1\lib" -
L"C:\Qt\4.1.1\lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4
tmp\obj\debug_shared\clem.o(.text$_ZN7cmdCallD1Ev[cmdCall::~cmdCall()]+0xb): In function `ZN6QFlagsIN2Qt13AlignmentFlagEEC1EPPv':
C:/MinGW/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/stl_algobase.h: undefined reference to `vtable for cmdCall'
tmp\obj\debug_shared\clem.o(.text$_ZN7cmdCallC1Ev[cmdCall::cmdCall()]+0x20):C:/MinGW/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/stl_algobase.h: undefined reference to `v
table for cmdCall'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\clem.exe] Error 1
mingw32-make[1]: Leaving directory `C:/Qt/4.1.1/clem'
mingw32-make: *** [debug-all] Error 2
If I remove the Q_OBJECT, it will compile but the DOS button does not do anything.
I've read the docs but I still got conceptual problems understanding the "Signals and Slots". Maybe with this example I will be able to understand it.
Clem
Keith Esau <keith.esau@xxxxxxx> wrote:Re: Spawning an MS DOS window The arguments in the SIGNAL() and SLOT() parameters must match. The clicked() signal sends no parameters, and system(const char*) is not a slot for QApplication and it requires a parameter.
You need to create an object with a slot that calls system(getenv("comspec")). (Not cmd.exe!)
class cmdCall : public QProcess
{
...
public slot:
void cmdexe() { execute(getenv("comspec")); };
...
}
Then in your code:
...
cmdCall sys;
...
QObject::connect(button1, SIGNAL(clicked()), &sys, SLOT(cmdexe()));
Keith
**Please do not reply to me, reply to the list.**
On 01-04-2008 6:24 PM, "Clement L. Rasul" wrote:
Hi! I am new to Qt. Can you get me up to speed on this. What seems
to be wrong with my code. I want to spawn an MS DOS window when a user
clicks the "DOS" button. My code are as follows:
#include <cstdlib>
#include <QObject>
#include <QApplication>
#include <QPushButton>
#include <QProcess>
#include <QStringList>
#include <QHBoxLayout>
int main( int argc, char *argv[] )
{
QApplication app(argc, argv);
QWidget * window = new QWidget;
window->setWindowTitle("SMIS");
QPushButton * button1 = new QPushButton("Dos");
QPushButton * button2 = new QPushButton("Quit");
QObject::connect(button1, SIGNAL(clicked()),
&app, SLOT( system("cmd.exe") ));
QObject::connect(button2, SIGNAL(clicked()),
&app, SLOT( quit() ));
QHBoxLayout * layout = new
QHBoxLayout;
layout->addWidget(button1);
layout->addWidget(button2);
window->setLayout(layout);
window->show();
return app.exec();
}
Quit() seems to work. But the system() does not. Am I missing
something. I've read through QProcess but the actual execution seems to escape
me.
Clem
Clement L. Rasul
e-mail: clemrasul@xxxxxxxxx
Clement L. Rasul
e-mail: clemrasul@xxxxxxxxx
---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.
I really recommend you go through some of the examples....
But it looks like you need to run qmake... And since you put both
classes in 1 file, you will need to include the output of moc.
Scott
________________________________
From: Clement L. Rasul [mailto:clemrasul@xxxxxxxxx]
Sent: Friday, January 04, 2008 10:43 PM
To: qt-interest@xxxxxxxxxxxxx
Subject: Re: Spawning an MS DOS window
If I understood you right, the code should be this way:
include <iostream>
#include <QObject>
#include <QApplication>
#include <QPushButton>
#include <QProcess>
#include <QHBoxLayout>
class cmdCall : public QProcess
{
Q_OBJECT
public slots:
void cmdexe() { execute(getenv("comspec")); };
};
int main( int argc, char *argv[])
{
QApplication app( argc, argv );
cmdCall sys;
QWidget * window = new QWidget;
window->setWindowTitle("SMIS");
QPushButton * button1 = new QPushButton("Dos");
QPushButton * button2 = new QPushButton("Quit");
QObject::connect(button1, SIGNAL(clicked()), &sys, SLOT(cmdexe()));
QObject::connect(button2, SIGNAL(clicked()), &app, SLOT( quit() ));
QHBoxLayout * layout = new QHBoxLayout;
layout->addWidget(button1);
layout->addWidget(button2);
window->setLayout(layout);
window->show();
return app.exec();
}
This one will not compile. I understand that I need to put the Q_OBJECT
in the class cmdCall. The compiler message are as follows:
C:\Qt\4.1.1\clem>MAKE
mingw32-make -f Makefile.Debug all
mingw32-make[1]: Entering directory `C:/Qt/4.1.1/clem'
g++ -c -g -g -frtti -fexceptions -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT
-DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN
-I"C:/Qt/4.1.1/include/QtCore" -I"C:/Qt/4.1.1
/include/QtGui" -I"C:/Qt/4.1.1/include" -I"."
-I"C:/Qt/4.1.1/include/ActiveQt" -I"tmp\moc\debug_shared" -I"."
-I"C:/Qt/4.1.1/mkspecs/win32-g++" -o tmp\obj\debug_shared\clem.o
clem.cpp
clem.cpp:37:2: warning: no newline at end of file
g++ -mthreads -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import
-Wl,-enable-runtime-pseudo-reloc -Wl,-subsystem,windows -o
"debug\clem.exe" tmp\obj\debug_shared\clem.o -L"C:\Qt\4.1.1\lib" -
L"C:\Qt\4.1.1\lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4
tmp\obj\debug_shared\clem.o(.text$_ZN7cmdCallD1Ev[cmdCall::~cmdCall()]+0
xb): In function `ZN6QFlagsIN2Qt13AlignmentFlagEEC1EPPv':
C:/MinGW/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits
/stl_algobase.h: undefined reference to `vtable for cmdCall'
tmp\obj\debug_shared\clem.o(.text$_ZN7cmdCallC1Ev[cmdCall::cmdCall()]+0x
20):C:/MinGW/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/
bits/stl_algobase.h: undefined reference to `v
table for cmdCall'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\clem.exe] Error 1
mingw32-make[1]: Leaving directory `C:/Qt/4.1.1/clem'
mingw32-make: *** [debug-all] Error 2
If I remove the Q_OBJECT, it will compile but the DOS button does not do
anything.
I've read the docs but I still got conceptual problems understanding the
"Signals and Slots". Maybe with this example I will be able to
understand it.
Clem
Keith Esau <keith.esau@xxxxxxx> wrote:
The arguments in the SIGNAL() and SLOT() parameters must match. The
clicked() signal sends no parameters, and system(const char*) is not a
slot for QApplication and it requires a parameter.
You need to create an object with a slot that calls
system(getenv("comspec")). (Not cmd.exe!)
class cmdCall : public QProcess
{
...
public slot:
void cmdexe() { execute(getenv("comspec")); };
...
}
Then in your code:
...
cmdCall sys;
...
QObject::connect(button1, SIGNAL(clicked()), &sys, SLOT(cmdexe()));
Keith
**Please do not reply to me, reply to the list.**
On 01-04-2008 6:24 PM, "Clement L. Rasul" wrote:
Hi! I am new to Qt. Can you get me up to speed on this. What seems
to be wrong with my code. I want to spawn an MS DOS window when a user
clicks the "DOS" button. My code are as follows:
#include <cstdlib>
#include <QObject>
#include <QApplication>
#include <QPushButton>
#include <QProcess>
#include <QStringList>
#include <QHBoxLayout>
int main( int argc, char *argv[] )
{
QApplication app(argc, argv);
QWidget * window = new QWidget;
window->setWindowTitle("SMIS");
QPushButton * button1 = new QPushButton("Dos");
QPushButton * button2 = new QPushButton("Quit");
QObject::connect(button1, SIGNAL(clicked()),
&app, SLOT( system("cmd.exe") ));
QObject::connect(button2, SIGNAL(clicked()),
&app, SLOT( quit() ));
QHBoxLayout * layout = new
QHBoxLayout;
layout->addWidget(button1);
layout->addWidget(button2);
window->setLayout(layout);
window->show();
return app.exec();
}
Quit() seems to work. But the system() does not. Am I missing
something. I've read through QProcess but the actual execution seems to
escape
me.
Clem
Clement L. Rasul
e-mail: clemrasul@xxxxxxxxx
Clement L. Rasul
e-mail: clemrasul@xxxxxxxxx
________________________________
Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try
it now.
<http://us.rd.yahoo.com/evt=51733/*http:/mobile.yahoo.com/;_ylt=Ahu06i62
sR8HDtDypao8Wcj9tAcJ%20>
I am overwhelmed with information. I read through the docs that I can google online and bought the book my blanchette and summerfield, still I am lost. For a newbie like me, its usually the first encounter that is the hardest. Code snippets may not be that useful to me being a newbie, every line and word I have to figure out the meaning. But I guess, if I can be helped just to go over the hump, I will be able to figure it out.
Keith, following your explanation, can you pinpoint what seems to be wrong with my revised code. Or if you can give me a sample code with a single button that will spawn an MS DOS window that will be much helpful in my understanding of Qt.
Thanks!
Clem
My code as follows:
#include <iostream>
#include <QObject>
#include <QApplication>
#include <QPushButton>
#include <QProcess>
#include <QHBoxLayout>
class cmdCall : public QProcess
{
Q_OBJECT
public slots:
void cmdexe() { execute(getenv("comspec")); };
};
int main( int argc, char *argv[])
{
QApplication app( argc, argv );
cmdCall sys;
QWidget * window = new QWidget;
window->setWindowTitle("SMIS");
QPushButton * button1 = new QPushButton("Dos");
QPushButton * button2 = new QPushButton("Quit");
QObject::connect(button1, SIGNAL(clicked()), &sys, SLOT(cmdexe()));
QObject::connect(button2, SIGNAL(clicked()), &app, SLOT( quit() ));
QHBoxLayout * layout = new QHBoxLayout;
layout->addWidget(button1);
layout->addWidget(button2);
window->setLayout(layout);
window->show();
return app.exec();
}
Keith Esau <keith.esau@xxxxxxx> wrote:
The arguments in the SIGNAL() and SLOT() parameters must match. The clicked() signal sends no parameters, and system(const char*) is not a slot for QApplication and it requires a parameter.
You need to create an object with a slot that calls system(getenv("comspec")). (Not cmd.exe!)
class cmdCall : public QProcess
{
...
public slot:
void cmdexe() { execute(getenv("comspec")); };
...
}
Then in your code:
...
cmdCall sys;
...
QObject::connect(button1, SIGNAL(clicked()), &sys, SLOT(cmdexe()));
Keith
**Please do not reply to me, reply to the list.**
On 01-04-2008 6:24 PM, "Clement L. Rasul" wrote:
Hi! I am new to Qt. Can you get me up to speed on this. What seems
to be wrong with my code. I want to spawn an MS DOS window when a user
clicks the "DOS" button. My code are as follows:
#include <cstdlib>
#include <QObject>
#include <QApplication>
#include <QPushButton>
#include <QProcess>
#include <QStringList>
#include <QHBoxLayout>
int main( int argc, char *argv[] )
{
QApplication app(argc, argv);
QWidget * window = new QWidget;
window->setWindowTitle("SMIS");
QPushButton * button1 = new QPushButton("Dos");
QPushButton * button2 = new QPushButton("Quit");
QObject::connect(button1, SIGNAL(clicked()),
&app, SLOT( system("cmd.exe") ));
QObject::connect(button2, SIGNAL(clicked()),
&app, SLOT( quit() ));
QHBoxLayout * layout = new
QHBoxLayout;
layout->addWidget(button1);
layout->addWidget(button2);
window->setLayout(layout);
window->show();
return app.exec();
}
Quit() seems to work. But the system() does not. Am I missing
something. I've read through QProcess but the actual execution seems to escape
me.
Clem
Clement L. Rasul
e-mail: clemrasul@xxxxxxxxx
Clement L. Rasul
e-mail: clemrasul@xxxxxxxxx
---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.
Clement L. Rasul
e-mail: clemrasul@xxxxxxxxx
---------------------------------
Looking for last minute shopping deals? Find them fast with Yahoo! Search.
Clement L. Rasul wrote: >Keith, following your explanation, can you pinpoint what seems to be > wrong with my revised code. Or if you can give me a sample code with a > single button that will spawn an MS DOS window that will be much > helpful in my understanding of Qt Your code declares the class with Q_OBJECT in a .cpp file. The Q_OBJECT macro expands to some function declarations that you need defined somewhere. It's moc's job to create the code that defines those functions. That means you must: 1) run moc over your .cpp file 2) #include the output at the bottom of your .cpp file If you're using qmake as your buildsystem, it does that automatically for you. You just need to add the #include statement at the bottom of the file. -- [ signature omitted ]
Attachment:
signature.asc
Description: This is a digitally signed message part.
In other words, move your class definition to a header (.h) file and fix your project (.pro) file accordingly. Then rerun qmake. Keith **Please do not reply to me, reply to the list.** On 01-05-2008 9:21 AM, "Thiago Macieira" wrote: > Clement L. Rasul wrote: >> Keith, following your explanation, can you pinpoint what seems to be >> wrong with my revised code. Or if you can give me a sample code with a >> single button that will spawn an MS DOS window that will be much >> helpful in my understanding of Qt > > Your code declares the class with Q_OBJECT in a .cpp file. > > The Q_OBJECT macro expands to some function declarations that you need > defined somewhere. It's moc's job to create the code that defines those > functions. > > That means you must: > 1) run moc over your .cpp file > 2) #include the output at the bottom of your .cpp file > > If you're using qmake as your buildsystem, it does that automatically for > you. You just need to add the #include statement at the bottom of the > file. -- [ signature omitted ]
Keith Esau wrote: >In other words, move your class definition to a header (.h) file and fix >your project (.pro) file accordingly. Then rerun qmake. No, that's not what I said. You can have the class definition in the .cpp, but you must then include the generated .moc file. -- [ signature omitted ]
Attachment:
signature.asc
Description: This is a digitally signed message part.
I know that's not what you said. I was trying to unconfuse things for our newbie. The SIMPLE way is to put the class definition in a .h file and include it in the project. Keith **Please do not reply to me, reply to the list.** On 01-05-2008 12:27 PM, "Thiago Macieira" wrote: > Keith Esau wrote: >> In other words, move your class definition to a header (.h) file and fix >> your project (.pro) file accordingly. Then rerun qmake. > > No, that's not what I said. > > You can have the class definition in the .cpp, but you must then include > the generated .moc file. -- [ signature omitted ]
Trolls, especially Thiago and Keith, many thanks! After figuring out what both of you are saying, I was able to successfully compile my Qt program according to the specs I wanted. I was thinking (after almost a day figuring it out), that creating a simple button that will spawn an MS DOS window in Qt should not be that hard. My guess is, there should be a simple how to (1 pager) for newbies. Also, the documentation (Qt Assistant) should have more examples similar to the ones available for PHP. Hmm... one of these days, if I am already at home with Qt... I'll volunteer to do it. Sources in the internet on Qt are still very scant. I tried googling and only a few pages came out. Some are even far out and not related to Qt. Anyway, again thanks for the big help! Clem Keith Esau <keith.esau@xxxxxxx> wrote: I know that's not what you said. I was trying to unconfuse things for our newbie. The SIMPLE way is to put the class definition in a .h file and include it in the project. Keith **Please do not reply to me, reply to the list.** On 01-05-2008 12:27 PM, "Thiago Macieira" wrote: > Keith Esau wrote: >> In other words, move your class definition to a header (.h) file and fix >> your project (.pro) file accordingly. Then rerun qmake. > > No, that's not what I said. > > You can have the class definition in the .cpp, but you must then include > the generated .moc file. -- [ signature omitted ] Message 11 in thread
On 06.01.08 06:00:28, Clement L. Rasul wrote: > Trolls, especially Thiago and Keith, many thanks! After figuring out what both of you are saying, I was able to successfully compile my Qt program according to the specs I wanted. > > I was thinking (after almost a day figuring it out), that creating a simple button that will spawn an MS DOS window in Qt should not be that hard. My guess is, there should be a simple how to (1 pager) for newbies. Also, the documentation (Qt Assistant) should have more examples similar to the ones available for PHP. Hmm... one of these days, if I am already at home with Qt... I'll volunteer to do it. Qt itself ships with a lot of examples, just look into the examples and demos subdir in your Qt installation. > Sources in the internet on Qt are still very scant. I tried googling and only a few pages came out. Some are even far out and not related to Qt. Have you checked QtCentre (qtcentre.org IIRC)? That should have a lot of information. Andreas -- [ signature omitted ]
I had the advantage of taking a class to begin my journey into Qt. Still, it
takes time to infuse all the aspects into your thinking. Stick with it. :)
There are quite a few good books available to step you through the basics
also:
<http://trolltech.com/developer/documentation/books>
Keith
**Please do not reply to me, reply to the list.**
On 01-06-2008 8:00 AM, "Clement L. Rasul" wrote:
> Trolls, especially Thiago and Keith, many thanks! After figuring out what
> both of you are saying, I was able to successfully compile my Qt program
> according to the specs I wanted.
>
> I was thinking (after almost a day figuring it out), that creating a simple
> button that will spawn an MS DOS window in Qt should not be that hard. My
> guess is, there should be a simple how to (1 pager) for newbies. Also, the
> documentation (Qt Assistant) should have more examples similar to the ones
> available for PHP. Hmm... one of these days, if I am already at home with
> Qt... I'll volunteer to do it.
>
> Sources in the internet on Qt are still very scant. I tried googling and only
> a few pages came out. Some are even far out and not related to Qt.
>
> Anyway, again thanks for the big help!
>
> Clem
>
On Jan 4, 2008 7:24 PM, Clement L. Rasul <clemrasul@xxxxxxxxx> wrote:
> Hi! I am new to Qt. Can you get me up to speed on this. What seems
> to be wrong with my code. I want to spawn an MS DOS window when a user
> clicks the "DOS" button. My code are as follows:
>
> #include <cstdlib>
> #include <QObject>
> #include <QApplication>
> #include <QPushButton>
> #include <QProcess>
> #include <QStringList>
> #include <QHBoxLayout>
>
> int main( int argc, char *argv[] )
> {
> QApplication app(argc, argv);
>
> QWidget * window = new QWidget;
> window->setWindowTitle("SMIS");
>
> QPushButton * button1 = new QPushButton("Dos");
> QPushButton * button2 = new QPushButton("Quit");
>
> QObject::connect(button1, SIGNAL(clicked()),
> &app, SLOT( system("cmd.exe") ));
>
> QObject::connect(button2, SIGNAL(clicked()),
> &app, SLOT( quit() ));
>
> QHBoxLayout * layout = new
> QHBoxLayout;
> layout->addWidget(button1);
> layout->addWidget(button2);
> window->setLayout(layout);
>
> window->show();
>
> return app.exec();
>
> }
>
>
> Quit() seems to work. But the system() does not. Am I missing
> something. I've read through QProcess but the actual execution seems to
> escape
> me.
You need to make a slot. You're trying to connect a signal to a slot
in QApplication called "system", which doesn't exist. If you're
intending to run the "system" library function, you're going to need
to write a slot wrapper to call it.
--
[ signature omitted ]
Clement L. Rasul wrote:
> QObject::connect(button1, SIGNAL(clicked()),
> &app, SLOT( system("cmd.exe") ));
Run your application in a debugging program or build it with OPTIONS +=
console in the .pro file.
You'll see that the line above prints a warning about there being no such
slot called:
system("cmd.exe")
in the QApplication class. You can take a look at the slot sections of
http://doc.trolltech.com/4.3/qapplication.html
and you'll see no such slot exists, really.
What you have not yet understood is the signal-slot mechanism of Qt. Take
a look at http://doc.trolltech.com/4.3/signalsandslots.html for more
information. But to answer the issue at hand: you can only connect a
signal to a function defined in one of the "slots" section of your
classes. And you cannot pass arbitrary parameters to them.
--
[ signature omitted ]
Attachment:
signature.asc
Description: This is a digitally signed message part.