Omnimaga
General Discussion => Technology and Development => Computer Programming => Topic started by: Sorunome on June 04, 2013, 10:43:36 pm
-
Inspired by jujus Browser Derp I made a Desktop Derp in C++ using QT! So far all it does is moving randomly around (with gif changing).
I'll have to come up with some good rules for which gif comes when (or make somebody else do that for me :P)
code upload soon!
-
Here we go (as promised): https://github.com/Sorunome/DesktopDerp
EDIT: I'm having trouble with a systemtrayicon and a rightclick-menu, if anybody wants to help me :D
-
Warning ! |\|00|3 question incoming ! 3... 2... 1...
How do I compile it ? I tried g++ main.cpp -o derpy but I have a no such file or directory error about QMainWindow (I installed the full Qt5 group in Arch).
I also tried qmake, make then ./DesktopDerp but it does nothing.
Edit : Aww... maybe I'm missing the GIFs ? :P
-
Edit : Aww... maybe I'm missing the GIFs ?
I downloaded a gif and it appears, I suggest using QMovie.isValid() ;)
BTW: Compiling with qt4 works, too.
EDIT: I'm having trouble with a systemtrayicon and a rightclick-menu, if anybody wants to help me :D
I may be able to help. Did you read http://qt-project.org/doc/qt-4.8/qsystemtrayicon.html#setContextMenu]http://qt-project.org/doc/qt-4.8/qsystemtrayicon.html#setContextMenu]http://qt-project.org/doc/qt-4.8/qsystemtrayicon.html#setContextMenu (http://qt-project.org/doc/qt-4.8/qsystemtrayicon.html#setContextMenu)?
It accepts a QMenu, like in http://qt-project.org/doc/qt-4.8/mainwindows-menus.html (http://qt-project.org/doc/qt-4.8/mainwindows-menus.html)
BTW2: http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/ (http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/) :P
-
Yeah in README.md it says Qt5 but in DesktopPonies.pro it says "greaterThan(QT_MAJOR_VERSION, 4)".
I've put a GIF and hardcoded the name to see it work, it looks like Derpy's just randomly moving around. You need to make her follow the mouse like Juju's ! :D
Edit : Whoops, didn't read the OP correctly I guess. :P Seriously, you owe it to the world. :trollface:
-
Yeah, i still have to upload the gifs, and i compile it over qt creator, it says it uses these lines (untested):
qmake /home/sorunome/desktopponies/DesktopPonies/DesktopPonies.pro -r -spec linux-g++-64 CONFIG+=debug CONFIG+=declarative_debug CONFIG+=qml_debug
make in /home/sorunome/desktopponies/build-DesktopPonies-Desktop-Debug
it just has to create the c++ files out of the .ui files and then make in the new directory.
EDIT: Yeah Vogtinator, i'll take a look, thanks
And I noticed a bug O.O after like a sertain number of gifs it just can't load new ones anymore, any idea why?
-
And I noticed a bug after like a sertain number of gifs it just can't load new ones anymore, any idea why?
While reading the source I noticed you're not freeing "QDesktopWidget *desk = new QDesktopWidget;", maybe that's the issue?
-
maybe, how do i free that? I've never done something like that in C++ >.>
-
As simple as it sounds:
desk = new QDesktopWidget;
free desk;
Edit: If you don't use pointers, it'll be done automatically if it gets out of scope, like this:
{
QDesktopWidget desk;
}
//desk will be freed
-
As simple as it sounds:
desk = new QDesktopWidget;
free desk;
uho, i need to decalre by QDesktopWidget *desk = new QDesktopWidget;
and free desk gives me the error that it expects a ; before desk
EDIT: but for soem reason i don't think it is the desk, because i just use that to check the boundries of the screen every frame.
-
Oh, sorry, I mistook free for delete,
delete desk;
should work.
-
Ok, let's see, it'll take like half an hour or longer.
BTW, can I somehow overgo the minimizing on when somkebody hits the show desktop button?
If not, can I somehow maximize my window?
-
Hmmm... That's why one shouldn't use two languages that are similar in the core but with little differences. :P
-
I added now the gifs to the repo :D
-
Ah cool. Pulling. :D
-
just make sure to move the gifs to your build directory, otherwise it won't work. It will compile+run without the gifs but there just won't be a derpy then.
-
Ok it works. BTW to compile you just do qmake then make.
-
really, that is awesome, i just looked at what qt creator sais it does, all that i need to do to compile is hit ctrl+r :P
And glad that you could compile it :D
EDIT: so Vogtinator, your fix doesn't work, it still stops running the new gifs after some time/some amount of gifs played, idk which one it is.
-
It will compile+run without the gifs but there just won't be a derpy then.
You can embed the .gifs as resource (e.g. /gifs/<name>.gif) and load them with ":/gifs/<name>.gif" as filename.
Ok it works. BTW to compile you just do qmake then make.
Better practice is to mkdir build, cd build, qmake .. and then make, so the source directory will be kept clean.
It's easier to exclude build in .gitignore than Makefile, *.o and the other output files.
, i just looked at what qt creator sais it does, all that i need to do to compile is hit ctrl+r
ctrl+b = build and F5 = debug.
BTW: If you use qDebug() << "asdf" instead of std::cout << "asdf", debug output will only be printed in debug build.
so Vogtinator, your fix doesn't work, it still stops running the new gifs after some time/some amount of gifs played, idk which one it is.
F5 will help you ;)
Edit: Some more advice:
- Don't allocate a QMovie everytime you change the animation. Set the filename by using QMovie::setFileName instead.
- To get the screen size use
QRect screen = qApp()->desktop()->screenGeometry()
- You can use the << operator instead of .append
possibleMoveActions.append("fly");
possibleMoveActions.append("flyupsidedown");
//Is the same as
possibleMoveActions << "fly" << "flyupsidedown";
-Use initialization lists:
//The contructor
derp() {
posx=500;
posy=500;
}
//does (almost) the same as
derp() : posx(500), posy(500)
{}
-You don't have to use an .ui file, you can add a QLabel as property of your MainWindow and add it using setCentralWidget(label)
-
thanks for all the tips! so what is the difference with
//The contructor
derp() {
posx=500;
posy=500;
}
//does (almost) the same as
derp() : posx(500), posy(500)
{}
as almost is not all the way :P
and that was how i append the lists, i didn't know how to use qlists :P
and a somehow wanne use a ui file, but this project is actually too simple to use one so i should step away from it, just lemme code a bit, maybe magically the bug with derpy vanishing will disappear :D
-
thanks for all the tips! so what is the difference with //The contructor
derp() {
posx=500;
posy=500;
}
//does (almost) the same as
derp() : posx(500), posy(500)
{}
as almost is not all the way :P
With initialization lists you can call the constructor of your parent classes and initialize const members.
http://www.cprogramming.com/tutorial/initialization-lists-c++.html (http://www.cprogramming.com/tutorial/initialization-lists-c++.html)
Actually, what happens in
class Foo {
private: int i;
public: Foo()
{
i = 1;
}
};
Is that i will be initialized to 0 first (default constructor) and later its value will be set.
and a somehow wanne use a ui file, but this project is actually too simple to use one so i should step away from it, just lemme code a bit, maybe magically the bug with derpy vanishing will disappear :D
That bug hasn't occured to me at all, but I noticed it's still invisible without .gifs.
-
I guess it is somehow filling up it's ram, i think that I fixed it, i'm testing it atm, i'll just run her for houres ^^
EDIT: All that I got around changing so far is - Don't allocate a QMovie everytime you change the animation. Set the filename by using QMovie::setFileName instead.
and the bug seem to be fixed, i'll still do the other suggestions though :D