Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

QT 3 MySQL Daten Ausgeben

Empfohlene Antworten

Veröffentlicht

hallo.. ich hab mal wieder ein problem mit meinem Programm =)... ich habe mir jetzt eine Datenbank angelegt indem ich mehrere Jahreszahlen hinterlegt habe (2008, 2009, usw) ... diese wollte ich jetzt in einer ComboBox anzeigen lassen aber irgendwie bekomme ich das nicht hin.. (später ordne ich zu den Jahreszahlen noch jeweils die Monate hinzu).

hier mal der code wie ich die daten von meiner datenbank abfrage:


	int abruf;

	MYSQL *connectionDB;

	MYSQL addDB;

	mysql_init(&addDB);

	connectionDB=mysql_real_connect(&addDB, "*****", "*****", "*****", "****", 0,0,0);

	string query= "select Jahr from Jahresverwaltung";

	abruf = mysql_query(connectionDB, query.c_str());



	close();

und hier nochmal meine ComboBox:

	jahr = new QComboBox(this);

	jahr->setGeometry(300,120,100,20);

	monat = new QComboBox(this);

	monat->setGeometry(420,120,100,20);

        static const char* items[] = { "Jahre", 0 };

        jahr->insertStrList( items );

hab da jetzt nur das Wort Jahre hingeschrieben =) ... später kommt halt der string da rein welcher dann alle anzeigt =)

hab auch schon drüber nachgedacht den string in ein array zu packen... kann mir aber net vorstellen das das klappen sollte =)

kann mir da jemand weiterhelfen?

:hells:

ja das ist ja mein problem =) ... ich hab keine ahnung wie ich das machen soll ... also ich schätz mal ich muss die Anfrage in einem string speichern? ... und dann muss ich das ja irgendwie in der tabelle ausgeben.. ich weiß nur nicht wie ;p

alles klar werd ich mir mal durchlesen =) ... danke

also ich hab jetzt nochmal geschaut wie ich eine anfrage abschicke... aber irgendwie geht das noch net so O.o

hier nochmal der code:

.h datei


#include <qpushbutton.h>

#include <qcombobox.h>

#include <qwidget.h>

#include <mysql/mysql.h>


class Window: public QWidget{

Q_OBJECT

private:

    QPushButton *anzeige;

    QComboBox *jahr;

    QComboBox *monat;


public:

    Window();

    ~Window();

    int numRow;

    MYSQL_RES* res;

    MYSQL_ROW rowContent;

    void jahrresverwaltungabruf();

};


.cpp datei

#include "window.h"

#include <iostream>

#include <qstring.h>


using namespace std;


Window::Window(){


//---------------Titel des Fensters-------------------------------

	this->setGeometry(0,0,1024,768);

	this->setCaption("Titel");

//-------------------------Combo Box-----------------------------

	jahr = new QComboBox(this);

	jahr->setGeometry(300,120,100,20);

        static const char* items[] = { "Jahre" , 0 };

        jahr->insertStrList( items );

//-------------------------Buttons-------------------------------

	anzeige = new QPushButton("Anzeigen", this);

	anzeige->setGeometry(540,120,100,20);


//-------------------------Connection Befehle--------------------

	connect(anzeige, SIGNAL(clicked()),this, SLOT(jahrresverwaltungabruf()));

	this->show();

}


//-------------------------Konstruktor und Destruktor------------

Window::~Window(){}


void Window::jahrresverwaltungabruf(){


	MYSQL *connectionDB;

	MYSQL addDB;

	mysql_init(&addDB);

	connectionDB=mysql_real_connect(&addDB, "localhost", "Benutzer", "Passwort", "verwaltung", 0,0,0);

    mysql_query(connectionDB, "Select Jahr from Jahresverwaltung;");

    res = mysql_store_result(connectionDB);


    rowContent = mysql_fetch_row(res);


    cout << rowContent << endl;



}

hab das zum test noch nicht eingebunden sondern erstmal wollte ich probieren ob er irgendwas in der konsole ausgibt... aber es kommt garnichts O.o

juhuuuu hab es nun hinbekommen das er wenigstens eine zahl ausgibt ;p

nur jetzt zerbreche ich daran den wert einzufügen O.o .. hab das jetzt so versucht:

.h datei



#include <qpushbutton.h>

#include <qcombobox.h>

#include <qwidget.h>

#include <mysql/mysql.h>


class Window: public QWidget{

Q_OBJECT

private:

    QPushButton *anzeige;

    QComboBox *jahr;

    QComboBox *monat;


public:

    Window();

    ~Window();


public slots:

    int jahrresverwaltungabruf();

};

.cpp datei

#include "window.h"

#include <iostream>

#include <qstring.h>


using namespace std;


Window::Window(){


//---------------Titel des Fensters-------------------------------

	this->setGeometry(0,0,1024,768);

	this->setCaption("Titel");

//-------------------------Combo Box-----------------------------

	jahr = new QComboBox(this);

	jahr->setGeometry(300,120,100,20);

        static const char* items[] = { "Jahre" , 0 };

        jahr->insertStrList( items );

//-------------------------Buttons-------------------------------

	anzeige = new QPushButton("Anzeigen", this);

	anzeige->setGeometry(540,120,100,20);


//-------------------------Connection Befehle--------------------

	connect(anzeige, SIGNAL(clicked()),this, SLOT(jahrresverwaltungabruf()));

	this->show();

}


//-------------------------Konstruktor und Destruktor------------

Window::~Window(){}


void Window::jahrresverwaltungabruf(){


int jahrresverwaltungabruf(){


	MYSQL *connectionDB;

	MYSQL_RES *result;

	MYSQL_ROW recordset_row;

	const char *strSQL;

	MYSQL addDB;

	mysql_init(&addDB);

	connectionDB=mysql_real_connect(&addDB, "localhost", "Benutzer", "Passwort", "verwaltung", 0,0,0);

	strSQL="SELECT Jahr FROM Jahresverwaltung;";

	mysql_query(connectionDB,strSQL);

	result=mysql_store_result(connectionDB);

	recordset_row=mysql_fetch_row(result);


	return recordset_row[0];



}

hab das versucht die Funktion jahrresverwaltungabruf so zu initialisieren das sie einen wert zurückgeben kann ... sprich den wert recordset_row[0] ... aber wenn ich es versuche zu kompilieren dann sagt er mir es ist nicht definiert ... also muss ich irgendwas falsch gemacht haben um den wert zurückzugeben... hat jemand ne ahnung wie ich das richtig machen kann?

ahh sorry xD .. hab ich falsch kopiert ;p

das void Window::jahrresverwaltungabruf(){

hatte ich gelöscht

es existiert nur

int jahrresverwaltungabruf()

das void Window::jahrresverwaltungabruf(){

hatte ich gelöscht

Du hast diese Methode aber in der Klassendefinition von Window definiert. Irgendein anderer Teil des Programms braucht sie vermutlich.

Ich glaube, ein C++-Grundlagentutorial wäre hier angebracht, bevor du dich in grafische Oberflächen und Datenbankzugriffe stürzt. ;)

guter tipp ;p ... hab mir jetzt zwar kein tutorial durchgelesen aber hab es jetzt hinbekommen ;p ... jahrresverwaltungabruf() hab ich nun wieder als void initialisiert und einfach im programm aufgerufen >< ... da hätte ich ja auch von allein drauf kommen können ;p

danke für deine hilfe! =)

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.