PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Brauche eure Hilfe -> Codebeispiel



Mat
01-10-2005, 12:14
Hallo
habe große Ansatzschwierigkeiten mit C++/Qt. Alles was ich will ist einfach bloß aus der Mainklasse eine andere Klasse aufrufen die mir ein MainWindow erstellt und da zum Beispiel einen Button darstellen lassen in dem fenster. Es soll ja mal ne Oberfläche werden...Bloß komme ich absolut nicht auf einen grünen Zweig. Ich bitte euch um Nachsicht...wenn ich erstmal in Fahrt komme legt sich das .......nur schaffe ich nicht mal das :(

warum funktioniert folgendes Beispiel bei mir nicht???

Projektart unter kdevelop: C++ -> Qmake -> Application

meine Klasse main:


#include <qapplication.h>
#include "runsimulation.h"

int main( int argc, char ** argv ) {
QApplication app( argc, argv );

RUNSIMULATION mw;
app.setMainWidget(&mw);
mw.show();
return app.exec();
}


das header file:



#ifndef RUNSIMULATION_H
#define RUNSIMULATION_H

#include <qmainwindow.h>

class QPushButton;

class RUNSIMULATION: public QMainWindow
{
Q_OBJECT

public:
RUNSIMULATION(QWidget *parent = 0, const char *name = 0);
//runsimulation();
// ~runSimulation();
void testemal();

private:
QPushButton *hello;

};
#endif


und zuletzt meine KLasse runsimulation die aufgerufen wird:


#include "runsimulation.h"

#include <qpushbutton.h>
#include <iostream.h>

RUNSIMULATION::RUNSIMULATION(QWidget *parent, const char *name): QMainWindow(parent,name)
{
testemal();
}

void RUNSIMULATION::testemal()
{
cout << "dies ist ein test" << endl;

hello = new QPushButton("jojoojoj", this);

//hello("Hello world!");
hello->resize(100, 30);
//hello->setMainWidget(this);
hello->show();
}


Danke euch für jede Mühe und hilfe

Mat
01-10-2005, 14:48
es geht doch.......seltsam......nach einem neustart von kdevelop geht es ?!???
:confused:

Mat
01-10-2005, 17:26
Hallo ich schaffe es einfach nicht meine zwei groupboxen im layoutmanager anzuzeigen....irgndwie erscheint immer nur das letzte widget:

meine klasse:


#include "mainwindow.h"
#include <qpushbutton.h>
#include <iostream.h>
#include <qgroupbox.h>
#include <qlayout.h>

MainWindow::MainWindow(QWidget *parent, const char *name): QMainWindow(parent,name)
{

gb_general = new QGroupBox("General", this);
gb_traces = new QGroupBox("Traces/Flags", this);
hello = new QPushButton("ja",gb_general);
qvBox = new QVBoxLayout;

qvBox->addWidget(gb_general);
qvBox->addWidget(hello);
//qvBox->addStrech(1);
cout << "Teste" << endl;
}


hier mein header file:


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <qmainwindow.h>

class QPushButton;
class QGroupBox;
class QLayout;
class Qgrid;

class MainWindow: public QMainWindow
{
Q_OBJECT

public:
MainWindow(QWidget *parent = 0, const char *name = 0);

private:
QPushButton *hello;
QGroupBox *gb_general;
QGroupBox *gb_traces;
QVBoxLayout *qvBox;
};
#endif


und zuletzt meine main:



#include <qapplication.h>
#include "mainwindow.h"

int main( int argc, char ** argv ) {
QApplication app( argc, argv );
MainWindow mw;
app.setMainWidget(&mw);
mw.setGeometry( 100, 100, 500, 355 );
mw.setCaption("Run Simulation Tool");
mw.show();
return app.exec();
}


ich weiß wirklich nicht wo das problem liegt....
danke für eure hilfe

anda_skoa
01-10-2005, 17:45
Das Layout hat keinen Parent.

Ich würde es so machen


MainWindow::MainWindow(QWidget *parent, const char *name): QMainWindow(parent,name)
{
QVBox* mainWidget = new QVBox(this);
setCentralWidget(mainWidget)

gb_general = new QGroupBox("General", mainWidget);
gb_traces = new QGroupBox("Traces/Flags", mainWidget);
hello = new QPushButton("ja",gb_general);

cout << "Teste" << endl;
}


Oder das Fenster gleich mit Designer machen.

Ciao,
_

Mat
02-10-2005, 15:43
Hallo Andre
vielen Dank für Alle Deine Antworten...ist wohl nicht immer leicht so viel gedult mit einem Anfänger zu haben :)

danke es funktioniert jetzt. Ich dachte mit meinem Code geht es dadurch dass ich this als parent übergebe aber anscheinend brauche ich noch ein extra parent!

Danke