Results 1 to 9 of 9

Thread: How can I solve this?

  1. #1
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default How can I solve this?

    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
    Qt Code:
    1. using namespace std;
    2.  
    3. char DLLfunction (){
    4. QLibrary myLib("dllprog");
    5. typedef char* (*MyPrototype)();
    6. MyPrototype myFunction =
    7. (MyPrototype) QLibrary::resolve("dllprog", "TestDll");
    8.  
    9. char *b = myFunction();
    10. return b;
    11. }
    To copy to clipboard, switch view to plain text mode 

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

    I am using QtCreator.

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How can I solve this?

    Hi,

    Just get the return value into a QString and show it into the widget(QLineEdit, QTextEdit,...).
    Òscar Llarch i Galán

  3. #3
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: How can I solve this?

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How can I solve this?

    Hi,

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

    Qt Code:
    1. QString qString(DLLfunction());
    To copy to clipboard, switch view to plain text mode 

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

    Then, you have the main window where you execute your code:
    Qt Code:
    1. myMainWindow::someMethod()
    2. {
    3. //Here you call your DLLfunction and show it to the QLineEdit
    4. QString qString(DLLfunction());
    5. ui.LineEdit->setText(qString);
    6. }
    To copy to clipboard, switch view to plain text mode 

    Take a look at "lineedit" examples on Qt dir.
    Òscar Llarch i Galán

  5. #5
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: How can I solve this?

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QString>
    3. #include <QLineEdit>
    4. #include "dialog.h"
    5. #include <QLibrary>
    6. #include <iostream>
    7. #include <windows.h>
    8.  
    9. using namespace std;
    10.  
    11. char DLLfunction()
    12. {
    13. QLibrary myLib("dllprog");
    14. typedef char* (*MyPrototype)();
    15. MyPrototype myFunction =
    16. (MyPrototype) QLibrary::resolve("dllprog", "TestDll");
    17. char b = myFunction();
    18. return b;
    19. }
    20.  
    21. QString qString(DLLfunction());
    22.  
    23. int main(int argc, char *argv[])
    24. {
    25.  
    26. QString qString(DLLfunction());
    27. ui.LineEdit->setText(qString);
    28.  
    29. QApplication a(argc, argv);
    30. Dialog w;
    31. w.show();
    32. return a.exec();
    33. }
    To copy to clipboard, switch view to plain text mode 

    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'

  6. #6
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can I solve this?

    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.

  7. #7
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How can I solve this?

    Qt Code:
    1. char DLLfunction()
    2. {
    3. QLibrary myLib("dllprog");
    4. typedef char* (*MyPrototype)();
    5. MyPrototype myFunction =
    6. (MyPrototype) QLibrary::resolve("dllprog", "TestDll");
    7. char b = myFunction();
    8. return b;
    9. }
    To copy to clipboard, switch view to plain text mode 
    there is something weird in your code as define MyPrototype as raturning char* and than you do:
    Qt Code:
    1. char b = myFunction();
    To copy to clipboard, switch view to plain text mode 
    where you are assigning returned value to one char. Is it right?
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  8. #8
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: How can I solve this?

    a mistake.

    the line now is

    Qt Code:
    1. typedef char (*MyPrototype)();
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: How can I solve this?

    I need a GUI application to display the contents of myFunction. I have a working console application.

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QLibrary>
    4. #include <QLineEdit>
    5. MainWindow::MainWindow(QWidget *parent)
    6. : QMainWindow(parent), ui(new Ui::MainWindowClass)
    7. {
    8.  
    9. ui->setupUi(this);
    10.  
    11. QLibrary myLib("dllprog");
    12. typedef char* (*MyPrototype)();
    13. MyPrototype myFunction = (MyPrototype) QLibrary::resolve("dllprog", "TestDll");
    14.  
    15. char* b = myFunction();
    16. ui->lineEdit->setText(b);
    17.  
    18. }
    19.  
    20. MainWindow::~MainWindow()
    21. {
    22. delete ui;
    23. }
    To copy to clipboard, switch view to plain text mode 

    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.

Similar Threads

  1. How to solve this cc1plus: out of memory problem?
    By triperzonak in forum Qt Programming
    Replies: 2
    Last Post: 28th September 2008, 20:20
  2. How to solve simultanious equations...??
    By joseph in forum General Programming
    Replies: 2
    Last Post: 28th May 2008, 10:53
  3. start application: Why this error and how to solve it?
    By Colx007 in forum Qt Programming
    Replies: 1
    Last Post: 21st January 2008, 15:22
  4. why qte2.3.1 can kill tty? how to solve it?
    By gwhhwgy in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 25th July 2006, 19:59
  5. Replies: 12
    Last Post: 3rd April 2006, 06:11

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.