It sort of worked but I think its printing out the memory address or something because its all hex...
Here is the output and this is for 3 inputs:
7.95446e-322
1.1117e-316
6.91643e-310
2.24083e-311
211
8.91041e-317
thats not hex...those are just realllllllllllllly small numbers think there is something wrong what is the code you are using to get the value?
First of all, C isn't a GUI programming language, it is a I/O lower level language so you don't do things like sql, spinboxes and widgets its more programming like microchips...
Second of all, as you can see I'm still a novice to qt/c++ and nearly every programming language in the "C-Family" works in the same way, don't mean you can use em all the same way.
Personally I think qt/c++ is the best tool for GUI Programming period. So I'm trying to learn by practising and doing something worthwhile at the same time. Excuse me for seeking help in the Qt/Programming forum for help...
Back to the thread we're actually meant to be discussing not my programming knowledge of the C-Family...If you know how to get the values please tell me or let me work.
Thank you
--
Qt Code:
int numberofpeople = ui->verticalLayout->count(); div(numberofpeople,2); for(int i = 0; i<numberofpeople; i++){ qDebug() << spinboxValues[i]; }To copy to clipboard, switch view to plain text mode
well the number of people is how many people input values for example if you have two ppl that input values the number of people is two. im not sure what that verticalLayout is.
and what are you using to actually get the value from the spinbox? are you using this on the okButtonslot?Qt Code:
value = ui->spinboxName->value()To copy to clipboard, switch view to plain text mode
Yes I'm getting the values from when the okButton is clicked. The VerticalLayout is used to layout the names+spinboxes in as the name says a vertical layout. I'm dynamically adding the labels and spinboxes to it by the amount of people in the database at the time of creation. I half the value of the numberofpeoples because I have a label+spinbox for each person so thats just math. Whether I'm doing it the right way is what I'm not sure about.
C and C++ are both general purpose languages. You can implement a graphical user interface as well using C (e.g. using GTK+ or WinAPI) as you can with C++ (e.g. using Qt or MFC).
That's not true either. Most database client drivers (e.g. libmysql, libpg, etc.) were written in C or at least expose a C compatible interface which allows them to be used from within virtually any programming language out there that allows calling external routines.it is a I/O lower level language so you don't do things like sql,
C++ was first developed by Bjarne Stoustrup around 1979 as an extension to C (its original name was "C with classes" later renamed to C++ which stands for "one more than C") and is 99% forward compatible with C. First widely acknowleged graphical user interface was created in 1963 (so even before C language was created) in Xerox labs (application was called Sketchpad) for a platform much weaker than todays microcontrollers so you can see there is no fixed relation between GUI, microchips and programming languages. If you want to go into discussions about programming languages then do your homework first and research the subject.spinboxes and widgets its more programming like microchips...
So learn to walk first before you sign in for a marathon.Second of all, as you can see I'm still a novice to qt/c++
You can write your program in C and compile it with a C++ compiler and it will work exactly the same way as if you built it with a C compiler. If you're familiar with C then go ahead and build your UI with what you know -- you don't have to implement any classes or use any other C++ features to create a simple user interface using Qt (at least since Qt5 where you can connect signals to arbitrary functions).and nearly every programming language in the "C-Family" works in the same way, don't mean you can use em all the same way.
So far you are trying to learn by having others do your tasks for you. Save yourself trouble, spend a week with a C++ book and then come back to your original project. I assure you it will pay back. Otherwise you'll be scratching your head forever wondering why you get random values from an uninitialized array which suggests your issues are something more than simply lack of C++ skills. Sorry to be so blunt but I'm way past my days of political correctness (if anyone wants to discuss that, I invite them to Warsaw for a beer or a cup of coffee). If you want to learn programming then do it by learning and then programming and not vice versa.So I'm trying to learn by practising and doing something worthwhile at the same time.
Ok I can be blunt too, you are acting ignorant especially since you say people program GUI's in C haha. Everyone knows c++ and java are used more for GUI programming because they are OBJECT ORIENTED. Of course its not impossible but who does GUIs in C???? Once you know C you can program in all of the C family. And are you really aruguing the fact that C is a low-level langauge???Really??? I've written nearly a thousand lines of C++ code for this singular program just because you feel you know everything about C++ doesn't mean everyone you come in contact with has to aswell. I'm sure you're a nice person in the real world but you really come across as rude and abrasive here. So you can save yourself the trouble and pick up a book on communication/interpersonal skills and come back to helping people you believe aren't as knowledgeable as you on forums.
GTK+/Qt are nearly identical in implementation, I don't know why you would even mention that. They are both OBJECT-ORIENTED. And also, GTK isn't available for all versions of Linux and seeing as Qt is native to my version of Linux...
Thanks I might upgrade to Qt 5.
Last edited by Cyrebo; 31st March 2013 at 10:46.
Well, you can laugh all you want but this won't change the fact that people do program GUI in C.
I don't see how this is relevant to anything. I'm not saying C++ is not used for GUI programming, I'm saying C is a general purpose language that is fit for UI programming.Everyone knows c++ and java are used more for GUI programming because they are OBJECT ORIENTED.
You'd be surprisedOf course its not impossible but who does GUIs in C????
Your case proves you wrong. You know C (at least you say so and I have no reason to not believe you) but apparently currently you are not able to program in C++.Once you know C you can program in all of the C family.
I'm not arguing anything however the level of C and C++ is usually considered the same (I wouldn't call it "low level" though -- assembly is low level, C/C++ is definitely higher level than assembly). Both are strongly typed, compiled, native symbol based languages. The fact that one is more object oriented than the other doesn't influence the level of the language.And are you really aruguing the fact that C is a low-level langauge???
Well, that's your problem, not mine. I'm not saying I could do the same in 400 lines of code but then I'm not saying I couldn't either.I've written nearly a thousand lines of C++ code for this singular program
I never said I know everything about C++. But I do know similarities and differences between programming languages I use.just because you feel you know everything about C++
I never said that too. The point is that you will gain much more if you focus on learning the language first before you start using it with a framework as complex as Qt. I noticed that I'm not the only one to tell you that. If one person tells you there is something wrong with you, you can ignore him. If two people tell you that you are sick -- think about seeing a doctor.doesn't mean everyone you come in contact with has to aswell.
Nnnno.... GTK+ is written in C, Qt is pure C++ -- how come possibly would they be "nearly identical" in implementation?GTK+/Qt are nearly identical in implementation
No, they are not.They are both OBJECT-ORIENTED
This is the official GTK+ "hello world" tutorial (with comments stripped out) :
C Code:
#include <gtk/gtk.h> static void hello( GtkWidget *widget, gpointer data ) { g_print ("Hello World\n"); } static gboolean delete_event( GtkWidget *widget, GdkEvent *event, gpointer data ) { g_print ("delete event occurred\n"); return TRUE; } /* Another callback */ static void destroy( GtkWidget *widget, gpointer data ) { gtk_main_quit (); } int main( int argc, char *argv[] ) { GtkWidget *window; GtkWidget *button; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (window, "delete-event", G_CALLBACK (delete_event), NULL); g_signal_connect (window, "destroy", G_CALLBACK (destroy), NULL); gtk_container_set_border_width (GTK_CONTAINER (window), 10); button = gtk_button_new_with_label ("Hello World"); g_signal_connect (button, "clicked", G_CALLBACK (hello), NULL); g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window); gtk_container_add (GTK_CONTAINER (window), button); gtk_widget_show (button); gtk_widget_show (window); gtk_main (); return 0; }To copy to clipboard, switch view to plain text mode
Where do you see anything object oriented here?
Fundamental concepts of object-oriented programming are abstraction, encapsulation, polymorphism and inheritance. The code I quoted is just a set of plain function calls -- no polymorphism, no encapsulation, no inheritance and practically no abstraction, no objects.
GTK doesn't care about your Linux version. The fact that your distro may be missing precompiled packages for GTK doesn't mean you can't build GTK for it.And also, GTK isn't available for all versions of Linux
This discussion is going nowhere. The primary fact (ignoring all the other things) is that you are trying to use a language you don't know and which makes you confused and I (we?) am telling you to focus on the language itself (without Qt, just plain C++) before trying to employ it to solve complex problems. Without knowledge about classes, inheritance, using and overriding virtual methods you will not be able to use Qt efficiently. You can learn all that in a couple of days and then you will have a chance to understand how to use Qt. We can see that even scopes of visibility are giving you problems and they are the same in both C and C++. You either accept that fact or not.
I don't agree with everything you said but one important part of you speil is that I don't know C++ well enough to implement something on this scale on that point I agree. I will learn it more in the future, atleast I hope to, that and Qt which I really like now but the thing is I need to get this done so its not really a matter of learning c++ right now but getting my program finished before a certain deadline. If I get this part of reading the values from the spinbox, I don't think I will have any more major problems in the future in getting it done which is why I'm asking.
Last edited by Cyrebo; 31st March 2013 at 19:30.
No but I copy value's values to another variable inside my okButton slot...So it's like:
The following is in dbInfo()
Qt Code:
ui->verticalLayout->addWidget(label); ui->verticalLayout->addWidget(spinbox); values = spinbox->value();To copy to clipboard, switch view to plain text mode
Then okButton slot
Qt Code:
spinboxValues << values; for(int i = 0; i<numberofpeople; i++){ qDebug() << spinboxValues[i]; }To copy to clipboard, switch view to plain text mode
I'm getting this kind of output now for three spinboxes:
0
48
913
151259145
-1253538145
0
I was expecting 0,0,0 because Im only passing the initialised values which i thought would be default value of 0. How to get the user inputted values is what I need.
Last edited by Cyrebo; 31st March 2013 at 21:25.
if you know how many spinboxes you are going to be using you could do this on the headers private:Qt Code:
To copy to clipboard, switch view to plain text mode
then on your mainfunction put something like this to declare the itemsthen add how ever many spinboxes/labels you want at startup by adding them to the layout then send that amount to a variable called something like spinboxCount and on the okButtonSlot put something like this:Qt Code:
for(int i = 0; i<XAMOUNT; i++){ }To copy to clipboard, switch view to plain text mode
Qt Code:
layout->addWidget(spinBoxName[spinboxCount+1]); spinBoxCount += 1;To copy to clipboard, switch view to plain text mode
then after that you can get the value of each spinbox easy by doing likeQt Code:
for(int i = 0; i<spinBoxCount; i++){ values[i] = spinboxname[i]->value(); }To copy to clipboard, switch view to plain text mode
That's just the problem, I don't, the number is unknown as the spnboxes are created dynamically based on the number in the database. Is there no way to implement this if the number of spinboxes is unknown?
yes I actually just figured it out via my program lol
on the header put this:
and put this on your mainfunction dbinfoQt Code:
QList<QSpinBox*> spinBoxes; QSpinBox *spinBox;To copy to clipboard, switch view to plain text modeand on your push button you are creating the spinboxes do thisQt Code:
QList<int> spinBoxesValue;To copy to clipboard, switch view to plain text mode
then just use a for loop to get the numbersQt Code:
spinBoxes << spinBox; for(int i = 0; i<spinBoxes.size();i++){ //add your widget how ever I am doing it by something like this layout->addWidget(spinBoxes[i],i+1;0); //get the value if you want when pressed otherwise put where you are getting spinBoxesValue << spinBoxes[i]->value(); }To copy to clipboard, switch view to plain text mode
Kinda got excited there for a second until I read the lastpart....Its a GUI and that way the user creates the spinboxes on button clicked. Is there a way this could work with the spinboxes dynamically created at run time and read the values on button clicked rather?and on your push button you are creating the spinboxes do this
I appreciate all the help from you on this![]()
U could put the buttons in a list then loop the signal from button x to spinhox x value
And have same slot for all buttons
Would this mean the spinboxes are added automatically when the form opens? The ok button then reads the values entered by the user on the form?
Where I said that ok button add widgets justt put that stuffvwhere u dynamically create then keep the value part then.cout it or w.e u doing to get the printed values
I misstead earlier on my phone
Got an error on this line.I substituted with my actual layout and it says expected ; got )layout->addWidget(spinBoxes[i],i+1;0);
What is it doing so I can make it sit well with the compiler?
The I+1;0 is supposed to be I+1,0 was a mistype and the I+1 is the row pos and 0 is column pos
And u need to declare layout by QGridLayout then create a QWidget and set the layout of the qwidget to that layout the set the qwidget as the central widget
Bookmarks