Hi,
I tried programming some GUI in Linux with C++ for the first time. Qt4 was recommended to me. Is that a good choice or does anybody have some better alternatives?
Now to my problem. I'm trying to program a calculator. First I built a little GUI with Qt-Designer and here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//--- main.cpp - start ---
#include "calculator.h"
#include <QApplication>
int main( int argc, char* argv[])
{
QApplication a(argc, argv);
Calculator w;
w.show();
return a.exec();
}
//--- main.cpp - end ---
LineEdit is the Line where you see the calculation. Button0 is a button with a zero which should insert a 0 in LineEdit. That's what the code does. But now I have also buttons with a 1,2,...,+,-,²,... and I don't want to create a new slot for each one.
Can the slots, which I defined, have arguments? like:
Qt is great. I have the Qt Creator open in my other screen right now. I'm also learning.
I wrote a program over the course of a week in pure Win32 with my own wrapper. I still had problems making it OOP, so I tried Qt and did the same thing over 4 hours (learning included).
As for slots, yes you need 1 slot per button. I know, it can be a little verbose. I was reading up on QCommandLinkButton, perhaps that can help. It's a cross between a radio button (mutually exclusive) and a pushbutton. Perhaps you can find a function that will return an index. The function would have to come from the parent window holding these buttons.
I was working on a number pad for a touchscreen app last night which is similar. Here's the source that I used. Note that I used the creator, so half of the stuff is in ui_numpad.h which has 158 boring lines so I won't post them here unless you are super interested. The only important stuff is that the editor makes a ui class. That class contains my pushbuttons and the QLineEdit called DisplayWindow. I made the slots all call the same function so that I could use Notepad++ to type on multiple lines at once. That made the multiple slots easy.