[Qt-interest] Qt Complex Data structure (user defined classes with QMap)
yogesh upreti
yogesh.upreti at gmail.com
Mon Apr 4 23:22:16 CEST 2011
Hello Jaco,
You got the mistake. Thanks my programme works again. One more thing which
is not working for me is
If I declear:
class SettingsClass {
public:
SettingsClass();
QMap<QString, QList<int> > *warning; //warning as pointer
};
then I can't access value at variable "warning" it as :
SettingsClass *set;
set->warning["some text"]; // this line throws error
Do you know how do I access it in that case???
Thanks again for help,
-Yogesh Upreti
On Mon, Apr 4, 2011 at 10:44 AM, Jaco Naude <naude.jaco at gmail.com> wrote:
> You never initialize set before using it. That will crash your program.
>
>
> this->set->warning["yogesh"] = list;
>
>
>
>
> On Mon, Apr 4, 2011 at 8:43 AM, Jaco Naude <naude.jaco at gmail.com> wrote:
>
>> Run it in debug mode and see where it crashes...
>>
>> On Mon, Apr 4, 2011 at 7:36 AM, yogesh upreti <yogesh.upreti at gmail.com>wrote:
>>
>>> Hello All,
>>>
>>> I am trying to make some complex data structure in Qt. My code looks like
>>> this (using Qt Creator) :
>>>
>>> main.cpp:
>>>
>>> #include <QtGui/QApplication>
>>>
>>> #include "mainwindow.h"
>>>
>>> int main(int argc, char *argv[])
>>>
>>> {
>>>
>>> QApplication a(argc, argv);
>>>
>>> MainWindow w;
>>>
>>> w.show();
>>>
>>> return a.exec();
>>>
>>> }
>>>
>>>
>>> mainwindow.h:
>>>
>>> #ifndef MAINWINDOW_H
>>>
>>> #define MAINWINDOW_H
>>>
>>> #include <QMainWindow>
>>>
>>> #include <QtGui>
>>>
>>> namespace Ui {
>>>
>>> class MainWindow;
>>>
>>> }
>>>
>>> class SettingsClass {
>>>
>>> public:
>>>
>>> SettingsClass();
>>>
>>> QMap<QString, QList<int> > warning;
>>>
>>> };
>>>
>>> class MainWindow : public QMainWindow
>>>
>>> {
>>>
>>> Q_OBJECT
>>>
>>> public:
>>>
>>> explicit MainWindow(QWidget *parent = 0);
>>>
>>> SettingsClass *set;
>>>
>>> ~MainWindow();
>>>
>>> private:
>>>
>>> Ui::MainWindow *ui;
>>>
>>> };
>>>
>>> #endif // MAINWINDOW_H
>>>
>>>
>>> mainwindow.cpp:
>>>
>>> #include "mainwindow.h"
>>>
>>> #include "ui_mainwindow.h"
>>>
>>> #include <QtGui>
>>>
>>> MainWindow::MainWindow(QWidget *parent) :
>>>
>>> QMainWindow(parent),
>>>
>>> ui(new Ui::MainWindow)
>>>
>>> {
>>>
>>> ui->setupUi(this);
>>>
>>> QList<int> list = QList<int>();
>>>
>>> list.append(1);
>>>
>>> list.append(2);
>>>
>>> list.append(3);
>>>
>>> list.append(4);
>>>
>>> list.append(5);
>>>
>>> this->set->warning["yogesh"] = list;
>>>
>>> QMapIterator<QString, QList<int> > itr(this->set->warning);
>>>
>>> while(itr.hasNext()){
>>>
>>> itr.next();
>>>
>>> QList<int> temp = itr.value();
>>>
>>> for(int i=0; i<temp.size();i++){
>>>
>>> ui->textEdit->insertPlainText(QString(">> %1: %2 -> %3\n").arg(itr.key()).arg(i).arg(temp.at(i)));
>>>
>>> }
>>>
>>> }
>>>
>>> }
>>>
>>> MainWindow::~MainWindow()
>>>
>>> {
>>>
>>> delete ui;
>>>
>>> }
>>>
>>>
>>>
>>> My programme compiles properly but its not running and exit with code
>>> -1073741819
>>> anyone knows what could be the problem with the user defined class??
>>>
>>> Thanks
>>> Yogesh Upreti
>>>
>>>
>>> _______________________________________________
>>> Qt-interest mailing list
>>> Qt-interest at qt.nokia.com
>>> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110404/cd19daea/attachment.html
More information about the Qt-interest-old
mailing list