Results 1 to 3 of 3

Thread: Problem During fatching records from QMAP container

  1. #1
    Join Date
    Sep 2011
    Posts
    20
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Problem During fatching records from QMAP container

    Hi All,

    I have one basic doubt that i have written one program and placed my map conatiner on one class and now i am trying to fetch records from another class with reference of existing class on which map conatiner is defined.But problem is that i am not getting records from different class.

    Following are the code

    Header definition for class on which i have defined MAP container
    #ifndef MAPCONFIG_H
    #define MAPCONFIG_H
    #include <QString>
    #include <QMap>

    class MapConfig
    {
    public:
    void mapconfig();
    QMap<QString,QString> map;
    QString find_key;
    QString msisdn_ip;

    };
    #endif // MAPCONFIG_H

    class Definition for above class
    #include <QFile>
    #include <QMessageBox>
    #include <QString>
    #include <QStringList>
    #include <QDebug>
    #include <QMap>

    #include "mapconfig.h"
    #include "findkey.h" //this is another class on which i am trying to fetch records from map container
    void MapConfig::mapconfig()
    {
    FindKey ob;
    QFile file("D:/CDR-LOADER/181011/config.txt");
    QString str;
    QStringList str_list;
    if(!file.open(QIODevice::ReadOnly|QIODevice::Text) )
    {
    QMessageBox::information(0,"Error","Error in opening file");

    }
    map.clear();
    while(!file.atEnd())
    {
    str = file.readLine();
    str_list = str.split("|");
    QString str_key = str_list.at(0) + str_list.at(1);
    QString str_value = str_list.at(2);
    qDebug()<<str_key<<" "<<str_value;

    map.insert(str_key,str_value);
    }
    file.close();
    find_key = "TS1";
    msisdn_ip = "6984";
    ob.findkey(find_key); //Passing "TS1" as key argument on findkey function
    }

    //header definition for FindKey Class

    #include <QString>
    class FindKey
    {
    public:
    void findkey(QString str_key);
    };

    //Class Definiton for FindKey Class

    #include <QFile>
    #include <QMessageBox>
    #include <QString>
    #include <QStringList>
    #include <QDebug>
    #include "findkey.h">
    #include "mapconfig.h"

    void FindKey::findkey(QString str_key)
    {
    mapconfig ob1;
    qDebug()<<"Inside Find Key"<<":"<<str_key; //Here its giving string value as "TS1"

    QString str_query;
    if(map.contains(str_key))
    {
    str_query=ob1.map.value(str_key);
    qDebug()<<str_query;

    }
    else
    {
    QMessageBox::warning(0,"Error","No value available for input key");

    }
    }
    qDebug of mapconfig class has given me value for key "TS1" but findkey class giving me ","No value available for input key".
    Can anybody help me why else part of code is executing. If i place this code inside same class on which i have placed mapconfig then code work properly.

    Please appologies me if it seem as dumb question but i am new on development and just started coding in QT.

    Thanks in advance.

    Lekhraj Deshmukh

  2. #2
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem During fatching records from QMAP container

    Basics of C++ say hello!
    Your method void MapConfig::mapconfig() is never called since it is not a cunstructor and it is never invoked by your code! C++ is case sensitive so "MapConfig" and "mapconfig" are completely different names, ergo "MapConfig::mapconfig()" it is not a constructor (it looks like this was your intention).

  3. #3
    Join Date
    Sep 2011
    Posts
    20
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem During fatching records from QMAP container

    Thanks Marek,got your point.

Similar Threads

  1. QMap problem
    By sophister in forum Qt Programming
    Replies: 8
    Last Post: 8th May 2009, 08:27
  2. Quick ? about qSort(Container & container)
    By JimDaniel in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2007, 11:20
  3. Problem with QMap
    By comlink21 in forum Qt Programming
    Replies: 1
    Last Post: 10th December 2007, 07:33
  4. Problem with Container Extension
    By tarod in forum Qt Tools
    Replies: 2
    Last Post: 12th November 2007, 16:20
  5. Problem with custom container widget
    By MrGarbage in forum Qt Tools
    Replies: 4
    Last Post: 25th August 2007, 03:37

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.