Seite 1 von 1

[GELÖST] zugriffsverletzung...

Verfasst: 8. Oktober 2007 17:39
von LQ
immer wenn ich bei einem label oder bei einer spinbox den jeweiligen set befehl (setText/setValue) in die main.cpp hinzufügen, kompiliert er ohne probleme,doch jammert das programm beim starten was über "zugriffsverletzung bei..."

die aktuellen codes schauen so aus:

ui_Interface.h:

Code: Alles auswählen

#ifndef UI_INTERFAcE_H
#define UI_INTERFAcE_H

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QCalendarWidget>
#include <QtGui/QFrame>
#include <QtGui/QLCDNumber>
#include <QtGui/QLabel>
#include <QtGui/QMainWindow>
#include <QtGui/QProgressBar>
#include <QtGui/QPushButton>
#include <QtGui/QStatusBar>
#include <QtGui/QWidget>

class Ui_mainWindow
{
public:
    QWidget *centralwidget;
    QLabel *label;
    QLabel *label_2;
    QLabel *label_3;
    QLabel *label_4;
    QCalendarWidget *calendarWidget;
    QProgressBar *dyingbar;
    QLabel *label_5;
    QLabel *label_6;
    QFrame *line;
    QLCDNumber *lifetimesconds;
    QLabel *label_7;
    QLabel *label_8;
    QPushButton *about;
    QPushButton *exit;
    QLCDNumber *AgeInSek;
    QLabel *output;
    QStatusBar *statusbar;

    void setupUi(QMainWindow *mainWindow)
    {
    if (mainWindow->objectName().isEmpty())
        mainWindow->setObjectName(QString::fromUtf8("mainWindow"));
    QSize size(627, 405);
    size = size.expandedTo(mainWindow->minimumSizeHint());
    mainWindow->resize(size);
    mainWindow->setWindowIcon(QIcon(QString::fromUtf8(":/mainicon.png")));
    centralwidget = new QWidget(mainWindow);
    centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
    label = new QLabel(centralwidget);
    label->setObjectName(QString::fromUtf8("label"));
    label->setGeometry(QRect(20, 20, 51, 21));
    QFont font;
    font.setFamily(QString::fromUtf8("MS Serif"));
    font.setPointSize(16);
    font.setBold(true);
    font.setItalic(false);
    font.setUnderline(false);
    font.setWeight(75);
    font.setStrikeOut(false);
    font.setKerning(true);
    label->setFont(font);
    label_2 = new QLabel(centralwidget);
    label_2->setObjectName(QString::fromUtf8("label_2"));
    label_2->setGeometry(QRect(210, 20, 371, 22));
    label_2->setFont(font);
    label_3 = new QLabel(centralwidget);
    label_3->setObjectName(QString::fromUtf8("label_3"));
    label_3->setGeometry(QRect(20, 60, 67, 22));
    label_3->setFont(font);
    label_4 = new QLabel(centralwidget);
    label_4->setObjectName(QString::fromUtf8("label_4"));
    label_4->setGeometry(QRect(210, 60, 114, 22));
    label_4->setFont(font);
    calendarWidget = new QCalendarWidget(centralwidget);
    calendarWidget->setObjectName(QString::fromUtf8("calendarWidget"));
    calendarWidget->setGeometry(QRect(20, 110, 200, 148));
    dyingbar = new QProgressBar(centralwidget);
    dyingbar->setObjectName(QString::fromUtf8("dyingbar"));
    dyingbar->setGeometry(QRect(230, 220, 391, 23));
    dyingbar->setValue(0);
    dyingbar->setOrientation(Qt::Horizontal);
    label_5 = new QLabel(centralwidget);
    label_5->setObjectName(QString::fromUtf8("label_5"));
    label_5->setGeometry(QRect(230, 120, 724, 41));
    label_5->setFont(font);
    label_6 = new QLabel(centralwidget);
    label_6->setObjectName(QString::fromUtf8("label_6"));
    label_6->setGeometry(QRect(230, 150, 724, 41));
    label_6->setFont(font);
    line = new QFrame(centralwidget);
    line->setObjectName(QString::fromUtf8("line"));
    line->setGeometry(QRect(-10, 280, 661, 20));
    line->setFrameShape(QFrame::HLine);
    line->setFrameShadow(QFrame::Sunken);
    lifetimesconds = new QLCDNumber(centralwidget);
    lifetimesconds->setObjectName(QString::fromUtf8("lifetimesconds"));
    lifetimesconds->setGeometry(QRect(280, 310, 131, 23));
    label_7 = new QLabel(centralwidget);
    label_7->setObjectName(QString::fromUtf8("label_7"));
    label_7->setGeometry(QRect(10, 310, 263, 22));
    label_7->setFont(font);
    label_8 = new QLabel(centralwidget);
    label_8->setObjectName(QString::fromUtf8("label_8"));
    label_8->setGeometry(QRect(420, 310, 200, 22));
    label_8->setFont(font);
    about = new QPushButton(centralwidget);
    about->setObjectName(QString::fromUtf8("about"));
    about->setGeometry(QRect(10, 350, 81, 31));
    exit = new QPushButton(centralwidget);
    exit->setObjectName(QString::fromUtf8("exit"));
    exit->setGeometry(QRect(530, 350, 81, 31));
    AgeInSek = new QLCDNumber(centralwidget);
    AgeInSek->setObjectName(QString::fromUtf8("AgeInSek"));
    AgeInSek->setGeometry(QRect(110, 60, 91, 23));
    output = new QLabel(centralwidget);
    output->setObjectName(QString::fromUtf8("output"));
    output->setGeometry(QRect(90, 20, 91, 21));
    mainWindow->setCentralWidget(centralwidget);
    statusbar = new QStatusBar(mainWindow);
    statusbar->setObjectName(QString::fromUtf8("statusbar"));
    mainWindow->setStatusBar(statusbar);

    retranslateUi(mainWindow);
    QObject::connect(exit, SIGNAL(clicked()), mainWindow, SLOT(close()));

    QMetaObject::connectSlotsByName(mainWindow);
    } // setupUi

    void retranslateUi(QMainWindow *mainWindow)
    {
    mainWindow->setWindowTitle(QApplication::translate("mainWindow", "Welcome", 0, QApplication::UnicodeUTF8));
    label->setText(QApplication::translate("mainWindow", "Noch", 0, QApplication::UnicodeUTF8));
    label_2->setText(QApplication::translate("mainWindow", "Sekunden bis zu ihrem n\303\244chsten Geburtstag.", 0, QApplication::UnicodeUTF8));
    label_3->setText(QApplication::translate("mainWindow", "Sie sind", 0, QApplication::UnicodeUTF8));
    label_4->setText(QApplication::translate("mainWindow", "Sekunden alt.", 0, QApplication::UnicodeUTF8));
    label_5->setText(QApplication::translate("mainWindow", "Wenn dieser Statusbalken voll ist, sind sie ", 0, QApplication::UnicodeUTF8));
    label_6->setText(QApplication::translate("mainWindow", "100 Jahre alt und wahrscheinlich schon tot.", 0, QApplication::UnicodeUTF8));
    label_7->setText(QApplication::translate("mainWindow", "Viel Spass noch mit den letzten", 0, QApplication::UnicodeUTF8));
    label_8->setText(QApplication::translate("mainWindow", "Sekunden ihres Lebens.", 0, QApplication::UnicodeUTF8));
    about->setText(QApplication::translate("mainWindow", "About", 0, QApplication::UnicodeUTF8));
    exit->setText(QApplication::translate("mainWindow", "Exit", 0, QApplication::UnicodeUTF8));
    Q_UNUSED(mainWindow);
    } // retranslateUi

};

namespace Ui {
    class mainWindow: public Ui_mainWindow {};
} // namespace Ui

#endif // UI_INTERFACE_H
main.cpp:

Code: Alles auswählen

 #include "QApplication.h"
 #include "QWidget.h"
 #include "QString"
 #include "QFile.h"
 #include "QTextStream.h"
 #include "QSettings.h"
 #include <iostream>
 #include <string>

 #include "ui_Interface.h"
	#include "ui_Configurator.h"

 QLabel *output;
 QLCDNumber *AgeInSek;
 int file1, file2, file3, time1, time2, time3;
 int temp1, temp2, temp3, temp4, temp5;
 unsigned long temp1x, temp2x, temp3x, temp4x, temp5x;
 int varix = 1;


 int main(int argc, char *argv[])
 {
	 QSettings settings("test", "tset");
	 settings.setValue("Identity/time", 1256);
	 settings.setValue("Identity/date1", 21);
	 settings.setValue("Identity/date2", 1);
	 settings.setValue("Identity/date3", 1965);


	 if (varix==1)
 {
     QApplication app(argc, argv);

     QMainWindow mainWindow;
     Ui::mainWindow ui;
     ui.setupUi(&mainWindow);   

	 temp1 = settings.value("Identity/date3").toInt();
	 temp1x = temp1 * 1892160000;

	output ->setText(QString::number(temp1x));

     mainWindow.show();
     return app.exec();

 } 
	 else
		 {
     QApplication app(argc, argv);

     QMainWindow Config;
     Ui::Config ui;
     ui.setupUi(&Config);

     Config.show();
     return app.exec();

 } 
 }
edit: falls sich jemand wundert: das mit der varix bdeingung hab ich eingefügt, um beide interfaces testen zu können. ich überleg mir für später ne andere bedingung.

Verfasst: 8. Oktober 2007 18:30
von Christian81
Zu viel code - Debugger anschmeissen und schauen an welcher Stelle der Fehler auftritt.

Verfasst: 8. Oktober 2007 18:32
von LQ
laut debugger in dieser zeile: (main.cpp)

Code: Alles auswählen

output ->setText(QString::number(temp1x));

Verfasst: 8. Oktober 2007 18:49
von Christian81
Habe ja gehofft Du kommst selbst drauf , aber leider nicht... :(

Was soll denn der ganze Müll da in der cpp-Datei:

Code: Alles auswählen

 QLabel *output;
 QLCDNumber *AgeInSek;
 int file1, file2, file3, time1, time2, time3;
 int temp1, temp2, temp3, temp4, temp5;
 unsigned long temp1x, temp2x, temp3x, temp4x, temp5x;
 int varix = 1;
Vor allem die ersten beiden...

Verfasst: 8. Oktober 2007 18:57
von LQ
die 2.zeile kann man ignorieren. (aus einem frühren test)

die 1.zeile hab ich hingeschrieben, weil er mir sonst jammert, dass "output" nirgends definiert ist. was soll ich sonst machen?

Verfasst: 8. Oktober 2007 19:08
von Christian81
LQ hat geschrieben: was soll ich sonst machen?
Dich erstmal mit der Objekt-orientierte Programmierung an sich auseinander setzen... :(

Verfasst: 8. Oktober 2007 19:13
von LQ
wie kann ich das in Interface.h definierte QLabel *output in der main.cpp verwenden?

Verfasst: 8. Oktober 2007 20:48
von LQ
ok, hat scih erledigt.

ich verdammter volltrotel: wie wär's, einfach mal die augen aufzusperren.

Verfasst: 8. Oktober 2007 21:18
von CaptnChaos
LOL!
Selbsterkenntiniss ist der erste Weg zur Besserung. Sagt der Volksmund!
Cool! :lol: