PDA

View Full Version : Basic question



giacomelli.fabio
17th December 2009, 18:50
Hello

I really don't understand how to do this thing :




QTimer::singleShot(1000,this,SLOT(dati("abc")));
QTimer::singleShot(2000,this,SLOT(dati("dfg")));
QTimer::singleShot(2000,this,SLOT(dati("hil")));

void SslClient::dati(QString testo) {
appendString(testo + "\n");
.........
}


obiovusly this is a semplification of what I need to do ...

I found into the forum similar question ( how to pass arguments ) ... but I need a very simple explanation becouse I'm starting now with Qt creator (before I used gambas for linux and it was very simplier :crying: ) and the help didn't clarify my doubt . I think also becouse of my bad english :o


Thank you in advance :p

Tanuki-no Torigava
17th December 2009, 21:15
Look here (http://www.qtcentre.org/forum/f-qt-programming-2/t-signal-and-slot-26352.html) please. Also, make use of the assistant and/or forum search function is nice idea, isn't it? ;)

wysota
17th December 2009, 21:40
Use QSignalMapper.


QSignalMapper *mapper = new QSignalMapper(this);
QTimer *t1 = new QTimer(this);
QTimer *t2 = new QTimer(this);
QTimer *t3 = new QTimer(this);
t1->setSingleShot(true);
t2->setSingleShot(true);
t3->setSingleShot(true);
connect(t1, SIGNAL(timeout()), mapper, SLOT(map()));
connect(t2, SIGNAL(timeout()), mapper, SLOT(map()));
connect(t3, SIGNAL(timeout()), mapper, SLOT(map()));
connect(mapper, SIGNAL(mapped(QString)), this, SLOT(dati(QString)));
mapper->setMapping(t1, "abc");
mapper->setMapping(t2, "def");
mapper->setMapping(t3, "ghi");
t1->start(1000);
t2->start(2000);
t3->start(3000);

giacomelli.fabio
17th December 2009, 22:10
mhmhmh a lot of code to do a so little thing ......
to pass an argument ....

Should I forget VB and it's simplicity ?

@ Tanuki-no Torigava I had already seen the post you linked , but I didn't understand nothing ! My english is not very good, so many little post, with various pieces of code ( i'm not good also qith qt creator ) make confusion . wysota's post is very clear :rolleyes:

wysota
18th December 2009, 00:12
Should I forget VB and it's simplicity ?
Yes, you should. Otherwise you'll be able to do only simple things and will never go beyond that. You can shorten my code by using a loop if you really want or you can avoid using signal mapper and do things the crude way - using a custom slot that will call the function with appropriate parameters.