February 22, 2011

sriharsha sriharsha
Lab Rat
5 posts

need a few clarifications

 

hi,
i am quite new to qt.i have done a exhaustive search but was not able to completely understand all the parameters in the code below. can anyone clarify what exactly a symbol .is it the name of a function present in a dll or is it smthin else. i have got the below from the qt documentation for QLibrary (http://doc.qt.nokia.com/4.7/qlibrary.html) but was not able to ubderstand completely.

  1. void * QLibrary::resolve ( const char * symbol )

12 replies

February 22, 2011

N3Roaster N3Roaster
Lab Rat
19 posts

You have the right idea. The symbol is the name of a function present in the library (DLL) specified in an earlier call to setFileName() and brought in with the load() method. The result is either a function pointer that can be used to call the specified function or (if resolve() failed) a null pointer.

February 22, 2011

sriharsha sriharsha
Lab Rat
5 posts

hi,
ty for ur reply N3Roster.
i found this program in the documentation. now here i understand in the below program that “avg” is the name of the function in the library but i am not able to understand what is “AvgFunction”. is it any random function pointer or a specific interface name in the dll.
thanks in advance.

  1. typedef int (*AvgFunction)(int, int);
  2.  
  3.  AvgFunction avg = (AvgFunction) library->resolve("avg");
  4.  if (avg)
  5.      return avg(5, 8);
  6.  else
  7.      return -1;

February 22, 2011

N3Roaster N3Roaster
Lab Rat
19 posts

QLibrary::resolve(), as seen in its prototype, returns a void pointer. The first line provides a function pointer type that specifies the return type and argument types which should match the function you want to call through that pointer. In the second line, AvgFunction is the pointer type for the avg variable the pointer is assigned to while (AvgFunction) to the right of the assignment casts the pointer returned from resolve() to that type. There’s nothing special about that name and it could be whatever makes sense in your application.

February 22, 2011

sriharsha sriharsha
Lab Rat
5 posts

hi,
thankyou N3Roaster for the reply.i really appreciate it.
i wrote a small snippet to access a function from the Apogee.dll file.Here is the code.

  1. #include <QtCore/QCoreApplication>
  2. #include<stdio.h>
  3. #include<QLibrary.h>
  4. int main(int argc, char *argv[])
  5. {     QCoreApplication a(argc, argv);
  6.     QLibrary asd("Apogee");
  7.     typedef bool (*ICamera2)(bool);
  8.     ICamera2 d=(ICamera2) Apogee->resolve("ShowIODialog");
  9.     bool ab;
  10.     ab=asd.load();
  11.     if(asd.isLoaded()==true)
  12.     {         printf("Loaded properly");
  13.        if(d(true))
  14.         {
  15.            d(true);
  16.        }
  17.        else
  18.        {
  19.            printf("not possible");
  20.        }
  21.     }
  22.     else
  23.     {
  24.         printf("not loaded");
  25.     }
  26.     return a.exec();
  27. }

but when i try to build my project it gives me an error ‘“Apogee” not declared in this scope’ .thanks in advance.

February 22, 2011

stuk stuk
Ant Farmer
523 posts

You have an error

  1. typedef bool (*ICamera2)(bool);
  2. ICamera2 d=(ICamera2) Apogee->resolve("ShowIODialog");

maybe you want

  1. typedef bool (*ICamera2)(bool);
  2. ICamera2 d=(ICamera2) asd->resolve("ShowIODialog");

sriharsha wrote:
hi,
thankyou N3Roaster for the reply.i really appreciate it.
i wrote a small snippet to access a function from the Apogee.dll file.Here is the code.
  1. #include <QtCore/QCoreApplication>
  2. #include<stdio.h>
  3. #include<QLibrary.h>
  4. int main(int argc, char *argv[])
  5. {     QCoreApplication a(argc, argv);
  6.     QLibrary asd("Apogee");
  7.     typedef bool (*ICamera2)(bool);
  8.     ICamera2 d=(ICamera2) Apogee->resolve("ShowIODialog");
  9.     bool ab;
  10.     ab=asd.load();
  11.     if(asd.isLoaded()==true)
  12.     {         printf("Loaded properly");
  13.        if(d(true))
  14.         {
  15.            d(true);
  16.        }
  17.        else
  18.        {
  19.            printf("not possible");
  20.        }
  21.     }
  22.     else
  23.     {
  24.         printf("not loaded");
  25.     }
  26.     return a.exec();
  27. }

but when i try to build my project it gives me an error ‘“Apogee” not declared in this scope’ .thanks in advance.

February 22, 2011

N3Roaster N3Roaster
Lab Rat
19 posts

Line 8 in your code. Change Apogee to asd.

February 22, 2011

sriharsha sriharsha
Lab Rat
5 posts

hi,
Stuk and N3Roaster, thankyou for your replies.i am able to compile my program properly thanks to you.but wen i run i get an error message . being quite new to this i have no idea whats wrong with my coding.i am attaching a snapshot of the error.
error snapshot
if the snapshot is not seen then i will repost it.

February 22, 2011

stuk stuk
Ant Farmer
523 posts

Nothing seen.

sriharsha wrote:
hi, Stuk and N3Roaster, thankyou for your replies.i am able to compile my program properly thanks to you.but wen i run i get an error message . being quite new to this i have no idea whats wrong with my coding.i am attaching a snapshot of the error. error snapshot if the snapshot is not seen then i will repost it.

February 22, 2011

sriharsha sriharsha
Lab Rat
5 posts

hi,
sory about that . i have attached again . it wil be available this time.
Error Snapshot

February 22, 2011

Volker Volker
Ant Farmer
5331 posts

A similar problem with Apogee was discusssed here [developer.qt.nokia.com].

Short story: You cannot resolve C++ symbols with QLibrary, only C symbols.

Longer story: you do not want to use QLibrary, but link to the DLL and use the header files provided for the DLL.

February 22, 2011

sriharsha sriharsha
Lab Rat
5 posts

hi,
ty volker for your reply. i tried to get the header files but it was not available so i was not able to that n has to resort to QLibrary.

February 22, 2011

Volker Volker
Ant Farmer
5331 posts

QLibrary is not a solution for C++ DLLs. You need the header files. Normally, those are provided in an SDK or the like.

 
  ‹‹ Unable to compile anything      QlistView click event in qt[closed] ››

You must log in to post a reply. Not a member yet? Register here!