Thanks man, I've been looking for something like that all day but I still get this error on runtime..
-build-desktop-Qt_4_8_3_in_PATH__System__Release/moc_mainwindow.cpp:-1: error: undefined reference to `MainWindow::dbinfoSlot()'
Thanks man, I've been looking for something like that all day but I still get this error on runtime..
-build-desktop-Qt_4_8_3_in_PATH__System__Release/moc_mainwindow.cpp:-1: error: undefined reference to `MainWindow::dbinfoSlot()'
because you need to put void before MainWindow more than likely.
like this:
Qt Code:
void MainWindow::somethingSlotIForgotName(){ //do something }To copy to clipboard, switch view to plain text mode
Edit:: if it is a private/slot you have to declare it as void/unsigned/int/ect
if it is the public function (the main one for the class) you do not have to declare it.
It was the name dbInfoSlot(), it was unused..I took that line out of the private slots and it worked but the program runs the function twice or something because it creates two instances of...I'll just show you
Qt Code:
void MainWindow::dbinfo() { int value; QSqlQuery qry; if (qry.exec("SELECT name FROM customers")) { while(qry.next()) { qDebug() << qry.value(0).toString(); if(qry.isValid()) { label->setGeometry(0,0,80,41); ui->verticalLayout->addWidget(label); ui->verticalLayout->addWidget(spinbox); value = spinbox->value(); qDebug() << value; } } } else { qDebug() << qry.lastError(); } }To copy to clipboard, switch view to plain text mode
I only want to create a label and spinbox for each customer but when I enter only 1 customer it creates two at run time...
do you have something else calling the dbinfo function? thats the onlything I can think of im still a beginner at qt/c++ haha
oh and the reason I put slot in the example was because if in your function you want you can connect in t he main fucntion like this:
Qt Code:
MainWindow::MainWindow(){ connect(pushButton,SIGNAL(clicked()), this,SLOT(functionSlot())); } MainWindow::functionSlot(){ //do something }To copy to clipboard, switch view to plain text mode
yes I called it twice, first with dbInfo(); then MainWindow::dbInfo();...
Do you know how to get the values from the spinbox for each person?
you could possibly send the values from the spinbox into a list of ints likeQt Code:
QList<int> spinboxValues; spinboxValues << value; for(int i = 0; i<numberofpeople; i++){ cout << spinBoxValues[i] << endl; }To copy to clipboard, switch view to plain text mode
So this action is triggered when i click another button which an ok button slot to get the figures. How may I use all the variables in my function. I know in c you just type in the variable function name but that doesn't work on c++...
do you mean use the variables form the other function? if this is what you mean you could try this:
Qt Code:
QList<double> spinboxValues; double values; mainWindow::dbinfo(){ //get values from spin box } void MainWindow::okbuttonslot(){ spinBoxValue << value; }To copy to clipboard, switch view to plain text mode
that would mean when you press the button the value from your spinbox would be appended to the QList spinbox but you will probably have to use a boolen or something if you use this method otherwise each time you press the button it will append it to the end
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
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.
Bookmarks