[gelöscht]
Hi Leute, mal wieder ich 😉
Ich bin grad dabei, mir das Beispielprogramm "AddressBook" des QtCreators reinzuziehen.
Obwohl der Project Wizard mir das Projekt automatisch erstellt hat, erhalte ich folgende Fehlermeldung:
/home/meinName/projects/Tutorials/part1/addressbook.cpp:83: error: invalid use of incomplete type ‘struct Ui::AddressBook’
Der Quelltext der addressbook.h sieht so aus:
#ifndef ADDRESSBOOK_H
#define ADDRESSBOOK_H
#include <QWidget>
#include <QMap>
#include <QMessageBox>
namespace Ui {
class AddressBook;
}
class AddressBook : public QWidget {
Q_OBJECT
public:
AddressBook(QWidget *parent = 0);
~AddressBook();
public slots:
void addContact();
void submitContact();
void cancel();
protected:
void changeEvent(QEvent *e);
private:
Ui::AddressBook *ui;
private:
QMap<QString, QString> contacts;
QString oldName;
QString oldAddress;
};
#endif // ADDRESSBOOK_H
Der Quelltext der addressbook.cpp sieht so aus:
#include "addressbook.h"
#include "ui_addressbook.h"
AddressBook::AddressBook(QWidget *parent) :
QWidget(parent),
ui(new Ui::AddressBook)
{
ui->setupUi(this);
ui->nameLine->setReadOnly(true);
ui->addressText->setReadOnly(true);
ui->submitButton->hide();
ui->cancelButton->hide();
connect(ui->addButton, SIGNAL(clicked()), this, SLOT(addContact()));
connect(ui->submitButton, SIGNAL(clicked()), this, SLOT(submitContact()));
connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
setWindowTitle(tr("Simple Address Book"));
}
AddressBook::~AddressBook()
{
delete ui;
}
void AddressBook::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void AddressBook::addContact()
{
oldName = ui->nameLine->text();
oldAddress = ui->addressText->toPlainText();
ui->nameLine->clear();
ui->addressText->clear();
ui->nameLine->setReadOnly(false);
ui->nameLine->SetFocus(Qt:😮therFocusReason);
ui->addressText->setReadOnly(false);
ui->addButton->setEnabled(false);
ui->submitButton->show();
ui->cancelButton->show();
}
void AddressBook::submitContact()
{
QString name = ui->nameLine->text();
QString address = ui->addressText->toPlainText();
if(name == "" || address == "")
{
QMessageBox::information(this, tr("Empty Field"), tr("Please enter a name and address"));
return;
}
if(!contacts.contains(name))
{
contacts.insert(name, address);
QMessageBox::information(this, tr("Add Successful"), tr("\"%1\" has been added to your address book.").arg(name));
}
else
{
QMessageBox::information(this, tr("Add Unsuccessful"), tr("Sorry, \"%1\" is already in your address book.").arg(name));
return;
}
if(contacts.isEmpty())
{
ui->nameLine->clear();
ui->addressText->clear();
}
ui->nameLine->setReadOnly(true);
ui->addressText->setReadOnly(true);
ui->addButton->setEnabled(true);
ui->submitButton->hide();
ui->cancelButton->hide();
}
Der Quelltext der main.cpp sieht so aus:
#include <QtGui/QApplication>
#include "addressbook.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
AddressBook w;
w.show();
return a.exec();
}
Also wie ich das sehe, ist der Quellcode richtig. Dennoch übersetzt er nicht 🙁.
Habe in den meisten Foren dazu nichts beziehungsweise nicht auf mein Problem genügend Aussagekräftiges gefunden.
Habt Ihr eine Lösung?