0

Hi I have problem with class objects and maybe You can solve it. That is my code:

Plugin.h:

    class DemandPlugin 
{

    public:
        QString sendtodb(QSqlDatabase &db, QString &cache, QString function);
        QSqlDatabase db;
        DemandPlugin();
        virtual ~DemandPlugin(); 
};

Plugin.cpp:

 DemandPlugin::DemandPlugin() 
{
     if (!db.open())
     {
         GlobalLog::log("SqlSource", "ERROR: Cannot connect to db!");
     }

     this->selectedPath = QString::null; 

/*
here are things which I don't want to show You, sorry ;)
*/
}

 QString DemandPlugin::sendtodb(QSqlDatabase &db, QString &cache, QString function)
   {
     QSqlQuery query(function,db);
     query.next();
     cache = query.value(0).toString();
     return cache;
   }
 DemandPlugin::~DemandPlugin() { }

These two files above are propably ok, they are located in one location in my project (Project/Subs/Demands/plugin.h , Project/Subs/Demands/plugin.cpp). The problem is with the third one. This file, called task.cpp is in loaction Project/Api/capi/task.cpp.

I want to use class object which is defined in "plugin" but it returns error: 'undefined reference to 'DemandPlugin::sendtodb(QSqlDatabase&, QString&, QString)'.

#include "../../Subs/Demands/plugin.h"

DemandPlugin *demand_plugin = new DemandPlugin();

double Task::getTotalCost()
{

    //return (costCoef * cost + baseCost) * waitCoef;

// //
    QString hostname = GlobalConfig::getValue("dbCredentials.ini", "database/host").toString();
    QString database = GlobalConfig::getValue("dbCredentials.ini", "database/db_name").toString();
    QString username = GlobalConfig::getValue("dbCredentials.ini", "database/user").toString();
    QString password = GlobalConfig::getValue("dbCredentials.ini", "database/password").toString();


    QString connectionName = QString::number((int)this, 16);
    QSqlDatabase db;
    db = QSqlDatabase::addDatabase("QPSQL", connectionName);
    db.setHostName(hostname);
    db.setDatabaseName(database);
    db.setUserName(username);
    db.setPassword(password);

    QString Worker_Name = GlobalConfig::getValue("cloud.ini", "name").toString();
    QString tbname;
    QString value;
    double infinity = std::numeric_limits<float>::infinity();
    QList <QString> tagnamevalue_tag;

    double new_cost;

         if(Worker_Name.contains("Luke") ==true)
            {

                QString line1 = "SELECT TAGS FROM TEST WHERE SUITE_ID = '"+ getParam("subs_test_id") +"'";

                tagnamevalue_tag = demand_plugin->sendtodb(db, value, line1).split(" ");

                QString part_of_query;
                for (int q=0; q<tagnamevalue_tag.count(); q++)
                {
                    part_of_query = part_of_query +"AND tags LIKE '%"+tagnamevalue_tag[q]+"%'";
                }

                QString line3 = "UPDATE Test SET selected = 'YES' WHERE id = (SELECT id FROM Testbays WHERE name LIKE '%Luke%' AND selected='NO'"+part_of_query+" ORDER BY id LIMIT 1) RETURNING name;";

                tbname = demand_plugin->sendtodb(db, value, line3);

                if(tbname == NULL)
                {
                    new_cost = infinity;
                }
                else
                {
                    new_cost = (costCoef * cost + baseCost) * waitCoef;
                }
            }    
return new_cost;
}
Lorn
  • 255
  • 2
  • 4
  • 10
  • 1
    Did you forget to compile `Plugin.cpp`? – eerorika Aug 18 '14 at 11:35
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Niall Aug 18 '14 at 11:41

0 Answers0