PDA

View Full Version : How can I solve this?



srohit24
17th March 2009, 16:17
I have a GUI application which has a push button and text area.

what i want the app to do is, when i press a push button, it should call a function that i have written and display its return value in the text area.

this is the function

using namespace std;

char DLLfunction (){
QLibrary myLib("dllprog");
typedef char* (*MyPrototype)();
MyPrototype myFunction =
(MyPrototype) QLibrary::resolve("dllprog", "TestDll");

char *b = myFunction();
return b;
}


how can get the return value in the GUI and in the text area.

I am using QtCreator.

^NyAw^
17th March 2009, 16:21
Hi,

Just get the return value into a QString and show it into the widget(QLineEdit, QTextEdit,...).

srohit24
17th March 2009, 18:55
can you explain it a bit further??

I have developed a console application but I am new to GUI and I have no idea how to add the signals and slots.

thanks for replying

^NyAw^
17th March 2009, 23:12
Hi,

You have a function called DLLfunction that returns a "char*", so:



QString qString(DLLfunction());


DLLfunction retunrs a "char*" and QString uses it to create the QString.

Then, you have the main window where you execute your code:


myMainWindow::someMethod()
{
//Here you call your DLLfunction and show it to the QLineEdit
QString qString(DLLfunction());
ui.LineEdit->setText(qString);
}


Take a look at "lineedit" examples on Qt dir.

srohit24
18th March 2009, 05:11
#include <QtGui/QApplication>
#include <QString>
#include <QLineEdit>
#include "dialog.h"
#include <QLibrary>
#include <iostream>
#include <windows.h>

using namespace std;

char DLLfunction()
{
QLibrary myLib("dllprog");
typedef char* (*MyPrototype)();
MyPrototype myFunction =
(MyPrototype) QLibrary::resolve("dllprog", "TestDll");
char b = myFunction();
return b;
}

QString qString(DLLfunction());

int main(int argc, char *argv[])
{

QString qString(DLLfunction());
ui.LineEdit->setText(qString);

QApplication a(argc, argv);
Dialog w;
w.show();
return a.exec();
}

this is my main.cpp code. This is the only page where I have written the code.

it says errors.


error: invalid conversion from `char*' to `char'
error: `ui' was not declared in this scope
warning: unused variable 'ui'

munna
18th March 2009, 05:23
I think you should start looking at the examples and tutorials that are part of the Qt installation to know more about signal & slots and UI development using Qt. Qt Assistant has every thing that you need to get started.

faldzip
18th March 2009, 07:09
char DLLfunction()
{
QLibrary myLib("dllprog");
typedef char* (*MyPrototype)();
MyPrototype myFunction =
(MyPrototype) QLibrary::resolve("dllprog", "TestDll");
char b = myFunction();
return b;
}

there is something weird in your code as define MyPrototype as raturning char* and than you do:


char b = myFunction();

where you are assigning returned value to one char. Is it right?

srohit24
18th March 2009, 09:28
a mistake.

the line now is


typedef char (*MyPrototype)();

srohit24
7th April 2009, 07:00
I need a GUI application to display the contents of myFunction. I have a working console application.


#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QLibrary>
#include <QLineEdit>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindowClass)
{

ui->setupUi(this);

QLibrary myLib("dllprog");
typedef char* (*MyPrototype)();
MyPrototype myFunction = (MyPrototype) QLibrary::resolve("dllprog", "TestDll");

char* b = myFunction();
ui->lineEdit->setText(b);

}

MainWindow::~MainWindow()
{
delete ui;
}

This is my code display the characters that myFunction returns in a linedit.

I have created a pushButton and a lineEdit in the .ui file.

I am getting this error.


:-1: error: collect2: ld returned 1 exit status

How can i solve this?

thanks for reading.