Flurite
|
  |
| Joined: 03 Apr 2011 |
| Total Posts: 5386 |
|
|
| 09 Apr 2012 11:23 AM |
Hi,
A while back, I remember trying to learn about the QTimer, but I didn't get it..
Anyway, now that I'm going back to the QTimer, I still have some questions, and I'm pretty sure it's stuff related to the Qt widget system. First of all, this is the sample code provided to make and run a timer:
QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(processOneThing())); timer->start();
the formatting is bad, but I'm assuming the connect function takes four arguments: the timer that is going to be connected, (IDK WAT SECOND ARGUMENT DOES), the "this" pointer, which points to the class the timer is in?, and the function in which the timer is connected to?
Could somebody explain to me what all the arguments are? Also, when I don't understand why I get an error when I put the "this" pointer in the top scope? |
|
|
| Report Abuse |
|
|
|
| 09 Apr 2012 11:27 AM |
This is a roblox lua discussion forum, not a C++ help forum. Try google or StackOverflow. |
|
|
| Report Abuse |
|
|
Flurite
|
  |
| Joined: 03 Apr 2011 |
| Total Posts: 5386 |
|
|
| 09 Apr 2012 11:31 AM |
You've told me this before, but I guess I'll explain. :P
-I don't think there's enough documentation on some Q stuff, so that becomes a problem.
-I was banned from asking questions on StackOverflow because I asked questions that quite a few thumbs down. :( |
|
|
| Report Abuse |
|
|
turbodaze
|
  |
| Joined: 17 Dec 2008 |
| Total Posts: 2169 |
|
|
| 09 Apr 2012 11:35 AM |
| I don't think this section of the forum forbids discussion of other languages, brandon. If there is a thread by a mod stating that it is limited to roblox lua, please link. |
|
|
| Report Abuse |
|
|
|
| 09 Apr 2012 11:40 AM |
better than
HOW 2 MAKE DA GRUP VIP?
so carry on flurite, I don't really think you're gonna get punished if those idiots don't ;) |
|
|
| Report Abuse |
|
|
Flurite
|
  |
| Joined: 03 Apr 2011 |
| Total Posts: 5386 |
|
|
| 09 Apr 2012 11:44 AM |
| I would probably continue to ask questions anyway until I get a ban or nobody helps me. :D |
|
|
| Report Abuse |
|
|
Flurite
|
  |
| Joined: 03 Apr 2011 |
| Total Posts: 5386 |
|
| |
|
Flurite
|
  |
| Joined: 03 Apr 2011 |
| Total Posts: 5386 |
|
|
| 09 Apr 2012 06:40 PM |
| Meh, I don't understand what they are referring to by the "this" pointer anyway. >_> |
|
|
| Report Abuse |
|
|
myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
|
| 09 Apr 2012 07:53 PM |
Qt uses a (weird) signal/slot system built on top of C++ using crazy preprocessors. The connect function accepts a signal and its class and the slot and its class. When the signal fires it calls that slot.
The this pointer is a predefined pointer in member functions of classes, and its just the pointer to the class your member function is in. |
|
|
| Report Abuse |
|
|
Flurite
|
  |
| Joined: 03 Apr 2011 |
| Total Posts: 5386 |
|
|
| 10 Apr 2012 02:22 PM |
Gee, thanks. Can I do something like this?
class X; { public: X(X* pntr) { cout << *pntr << "\n"; } };
int main() { X lol(this); }
??? epic sauz ??? |
|
|
| Report Abuse |
|
|
Flurite
|
  |
| Joined: 03 Apr 2011 |
| Total Posts: 5386 |
|
|
| 10 Apr 2012 02:35 PM |
I realized that you can't print a class, so I changed that around to this (ideone code): /aYd2X
But it gives me a very similar error to what I was working with:
error: invalid use of ‘this’ in non-member function |
|
|
| Report Abuse |
|
|
|
| 10 Apr 2012 03:13 PM |
When people go all out hacking C++ to have all that crazy syntax, I understand it (AFAIK), but it makes my eyes hurt so much
y u no just stick with regular syntax instead of hacking method pointers or whatever X lol(this) does |
|
|
| Report Abuse |
|
|
Flurite
|
  |
| Joined: 03 Apr 2011 |
| Total Posts: 5386 |
|
|
| 10 Apr 2012 03:34 PM |
| idk, that's how QTimer does it. |
|
|
| Report Abuse |
|
|
|
| 10 Apr 2012 03:47 PM |
| learn whatever C++ compiles into, and FIX IT NAO |
|
|
| Report Abuse |
|
|
Flurite
|
  |
| Joined: 03 Apr 2011 |
| Total Posts: 5386 |
|
|
| 10 Apr 2012 03:49 PM |
| compile C++? are you trolling me? |
|
|
| Report Abuse |
|
|
movable
|
  |
| Joined: 14 Mar 2011 |
| Total Posts: 69 |
|
|
| 10 Apr 2012 04:27 PM |
Trapping, I remember that Group VIP post. Well, I read it.
--Movable |
|
|
| Report Abuse |
|
|
myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
|
| 10 Apr 2012 07:48 PM |
this is used INSIDE the member function. It is passed automatically when calling a member function. For instance:
struct X { void eat(void) { *this // points to "pie" } }
X pie;
pie.eat(); |
|
|
| Report Abuse |
|
|
|
| 10 Apr 2012 07:50 PM |
"compile C++? "
when you click play it compiles it into some magic stuff and then you can learn that magic stuff to be even proer |
|
|
| Report Abuse |
|
|
myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
|
| 10 Apr 2012 07:52 PM |
| Except that magic stuff is hardly understandable, since the compiler could just inline the whole thing into a single function if it felt like it. |
|
|
| Report Abuse |
|
|
|
| 10 Apr 2012 07:54 PM |
| still possible to learn though |
|
|
| Report Abuse |
|
|
|
| 10 Apr 2012 07:54 PM |
| what does it compile into anyway? dynamic assembly? |
|
|
| Report Abuse |
|
|
Flurite
|
  |
| Joined: 03 Apr 2011 |
| Total Posts: 5386 |
|
|
| 10 Apr 2012 07:55 PM |
@myrkos,
Then how do they do that in QTimer? They pass "this" pointer as an argument. They even did it in my OP! D: |
|
|
| Report Abuse |
|
|
myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
|
| 10 Apr 2012 07:55 PM |
| Straight assembly, though with a few differences like local addresses and stuff which the linker has to take care of before launching the program. |
|
|
| Report Abuse |
|
|
myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
|
| 10 Apr 2012 07:56 PM |
| @flurite, because there you're supposedly calling the connect function inside a member function (most probably a constructor) of the class which has the slot/signal you want to connect. You don't have to do that; you could just pass the address of the class that has the signal/slot. |
|
|
| Report Abuse |
|
|
|
| 10 Apr 2012 07:57 PM |
"They pass "this" pointer as an argument"
If you mean return that's perfectly fine
If you mean pass it as an argument, I have no idea what you mean since I don't think you're creating an object, only instances of their object, so you didn't make anything for it to pass it to
@myrkos
the MOV 7, 0x2342343; BIN HAX BOM CHEZ 45, 4568 stuff, or like a super haxxy type which is even less understandable? |
|
|
| Report Abuse |
|
|