[Moved] Document/View application
-
No luck - below is the MainWindow and Information code. I left out the UserData code to see if this would work before making it any more complex. This generates a compile error code:
request for member 'a' in 'info', which is of non-class type 'Information*'
Is this caused by a syntax error that I am missing?
MainWindow.h
@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
#include "Information.h"namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();private:
struct information *info;private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
@MainWindow.cpp
@
#include "mainwindow.h"
#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{ui->setupUi(this); info = new information; info.a = "A"; info.b = "B"; info.c = "C";
}
MainWindow::~MainWindow()
{
delete ui;
}
@Information.h
@
#ifndef INFORMATION_H
#define INFORMATION_H#include <QtGui>
struct information
{
QString a;
QString b;
QString c;
};#endif // INFORMATION_H
@
Added @ tags around code sections. Please do that yourself next time; Andre
-
There seems to be some weird mismatch of #ifdefs and #endif's in your code. Perhaps you should fix these first?
Oh, and in your MainWindow, you have a pointer to an Information instance, while you do not seem to be creating an instance and trying to assign to it as if it is a normal member variable.
-
Did you also note the remark I posted above?
[quote author="Andre" date="1315495737"]Oh, and in your MainWindow, you have a pointer to an Information instance, while you do not seem to be creating an instance and trying to assign to it as if it is a normal member variable. [/quote]
-
Either, change line 20 in MainWindow.h to
@
Information info;
@
and remove line 13 from MainWindow.cpp, orchange line 20 in MainWindow.h to
@
Information* info;
@
and change lines 15-17 in MainWindow.cpp into:
@
info->a = "A";
info->b = "B";
info->c = "C";
@
and insert this line as line 24:
@
delete info;
@In either case, get yourself a good book on C++ to get yourself a solid introduction into the language you are working with. Qt does not shield you from having to learn C++.
-
Andre (and everyone else)-
Thanks for your help. The first option compiled correctly. Having seen something that works I hope I can figure it out from here.
Your last suggestion is appropriate. However, I have a large stack of books on C++ programming. The problem is the definition of the word "good". I learned chemical thermodynamics by using a large stack of textbooks. None of them were particulary good. But, where one authors explanation failed another author provided a more thorough explanation. I was able to piece it together that way. I haven't found that approach to work well for understanding C++.