Results 1 to 13 of 13

Thread: simple hello world question

  1. #1
    Join Date
    May 2006
    Location
    Philadelphia, PA USA
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Question simple hello world question

    If i have a cpp program that prints hello world to standard output,
    how do i put a gui on top of this standalone program? For example
    a button that runs the cpp hello world program...

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: simple hello world question

    You can use QProcess for this.

  3. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: simple hello world question

    Quote Originally Posted by chap19150
    If i have a cpp program that prints hello world to standard output,
    .
    This sample snipp search if window is online and ethernet work...

    the output from # ipconfig /all

    and process.readAll(); grab result....


    Qt Code:
    1. bool DB_Setup::TestGigaByte()
    2. {
    3. #if defined Q_WS_WIN
    4. bool onlinestatus;
    5. QString status; /* find Address to check if the gay is online! why? webdav disk stay on cache lifetime! :-( */
    6. QProcess process;
    7. process.setReadChannelMode(QProcess::MergedChannels);
    8. process.start("ipconfig" , QStringList() << "/all");
    9. if (!process.waitForFinished()) {
    10. status = process.errorString();
    11. } else {
    12. status = process.readAll();
    13. }
    14. onlinestatus = status.contains("address", Qt::CaseInsensitive);
    15. if (onlinestatus) {
    16. /*qDebug() << "### yes ethernet TestGigaByte " << onlinestatus;*/
    17. } else {
    18. /*qDebug() << "### no ethernet TestGigaByte " << onlinestatus; */
    19. }
    20. return onlinestatus;
    21. #endif
    22. return WebDavCheck(); /* other OS only check if the remote config file exist */
    23. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    May 2006
    Location
    Philadelphia, PA USA
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: simple hello world question

    ok, i think i understand QProcess but what if I want the programs to compile together
    on one makefile?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: simple hello world question

    Quote Originally Posted by chap19150
    ok, i think i understand QProcess but what if I want the programs to compile together
    on one makefile?
    But do you want two separate executables?

    Makefiles for Qt programs are a bit complex, so you use qmake or some other tool to generate them. qmake can't create a single Makefile for two executables, but you can place those programs in separate directories and use a .pro file with TEMPLATE="subdirs" --- this way qmake will generate a Makefile that will run Makefiles from subdirectories (in other words you will have more than one Makefile, but you will be able to compile all programs with a single "make").

  6. #6
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: simple hello world question

    Quote Originally Posted by chap19150
    ok, i think i understand QProcess but what if I want the programs to compile together
    on one makefile?
    If You like external programm must go inside qt.....
    make a static lib from the programm ...
    and on your header .... link the programm original header...
    .... and call the function easy from qt ....

    rewrite cout << to

    sprintf (buffer, "%s%s", one , dwo);
    return buffer;

    Sample static libs programm...
    http://ciz.ch/svnciz/_STATIC_LIBS_QT4/lib_tidy_src/
    have a look on
    http://ciz.ch/svnciz/_STATIC_LIBS_QT...b_tidy_src.pro

    Qmake can compile a lot of programm ... put source on a dir...

    cd dir .... qmake -project && qmake && make
    Grab error and clean the code...
    *** pro file LANGUAGE = C++ or LANGUAGE = C
    if the code is ok ... remove main.cpp and transform to static libs... and call function from qt....

  7. #7
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: simple hello world question

    Quote Originally Posted by jacek
    subdirectories (in other words you will have more than one Makefile, but you will be able to compile all programs with a single "make").
    As sample:

    Qt Code:
    1. TEMPLATE = subdirs
    2.  
    3. SUBDIRS = lib_sqlite_qt4 \
    4. date_qdialog \
    5. lib_tidy_src \
    6. lib_wgetqt_src \
    7. src_0
    To copy to clipboard, switch view to plain text mode 
    dir structure .....
    http://ciz.ch/svnciz/_STATIC_LIBS_QT4/

    compile on mac , linux , window .
    1- staticlibs from sqlite3
    2- qdate libs calendar designer plug-in as static libs...
    3- tidy libs to clean html bad & holocaust QTexEdit html
    4- wget libs & network & smtp auth funktion
    5- Final build the programm main.cpp included all libs.... the result one exe win or **.apps mac....
    Last edited by patrik08; 12th June 2006 at 14:45.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: simple hello world question

    Quote Originally Posted by patrik08
    rewrite cout << to

    sprintf (buffer, "%s%s", one , dwo);
    return buffer;
    Better use QString and QTextStream instead.

  9. #9
    Join Date
    May 2006
    Location
    Philadelphia, PA USA
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Question Re: simple hello world question

    Quote Originally Posted by jacek
    But do you want two separate executables?

    Makefiles for Qt programs are a bit complex, so you use qmake or some other tool to generate them. qmake can't create a single Makefile for two executables, but you can place those programs in separate directories and use a .pro file with TEMPLATE="subdirs" --- this way qmake will generate a Makefile that will run Makefiles from subdirectories (in other words you will have more than one Makefile, but you will be able to compile all programs with a single "make").
    ok, I have 2 directories /files/helloworld and /files/qtgui
    I have a makefile for the helloworld program. do I also
    have to put a .pro file in the helloworld directory also, and if
    so what would this contain?

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: simple hello world question

    Quote Originally Posted by chap19150
    do I also have to put a .pro file in the helloworld directory also, and if so what would this contain?
    No, you don't have to, but you need a .pro file in /files directory.

    Something like:
    Qt Code:
    1. TEMPLATE = subdirs
    2. SUBDIRS += ./helloworld ./qtgui
    To copy to clipboard, switch view to plain text mode 

  11. The following user says thank you to jacek for this useful post:

    chap19150 (12th June 2006)

  12. #11
    Join Date
    May 2006
    Location
    Philadelphia, PA USA
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default one more question

    ok so it seems that i need one executable. Essentially what I have
    is a full featured program that I need to put a gui on top of. The gui
    will call functions from the main program. I wanted to
    start with the hello world program just to see how it is done.

    any advice?

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: one more question

    Quote Originally Posted by chap19150
    ok so it seems that i need one executable. Essentially what I have
    is a full featured program that I need to put a gui on top of.
    If you want one executable, it means that you want a single program. Everything depends on the size of the original application and its design. If you can bypass its I/O routines, all you have to do is to implement their equivalents in Qt. If not, most likely you will have to implement screen scraping and for this you could try freopen() and pipe() (to intercept stdin, stdout and stderr).
    Last edited by jacek; 21st June 2006 at 20:15.

  14. #13
    Join Date
    Jan 2006
    Location
    USA
    Posts
    6
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: simple hello world question

    I was just doing this last week. Here's what I did:
    Make a cpp file that looks like this:

    #include <QApplication>
    #include "mainimpl.h"


    using namespace std;

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

    mainImpl window;

    return app.exec();
    }

    This creates a QT application and loads my class, mainImpl. mainImpl is an implementation of a form that I created. I'll now show an important part of mainImpl:
    the .cpp file:

    mainImpl::mainImpl(QWidget *parent) : QMainWindow(parent)
    {
    ui.setupUi(this);
    this->show();

    //some sample things that my program needs
    fillArray(geneNames);
    numLineGenes = 0;
    numExps = 0;

    //signal/slot for the exit button in the menu
    connect(ui.actionExit, SIGNAL(triggered()), QApplication::instance(), SLOT(quit()));
    }

    and the .h file:

    #include "ui_FormV4a.h"

    class mainImpl: public QMainWindow {

    Q_OBJECT

    public:
    mainImpl(QWidget *parent = 0);

    ~mainImpl();
    private:
    Ui::FrmReformatData ui;
    }

    You can then put all your subroutines from your original program into the mainImpl class. To use a button to run the subroutines, you need to use slots and signals. There are lots of things online that explain slots and signals.

    Hope that helped answer your question.

Similar Threads

  1. QTextEdit simple question
    By Marcopolo in forum Qt Tools
    Replies: 4
    Last Post: 11th October 2007, 00:01
  2. Simple Question on getExistingDirectory
    By Naveen in forum Qt Programming
    Replies: 6
    Last Post: 3rd March 2006, 09:44
  3. a simple question: spinbox
    By mickey in forum Newbie
    Replies: 3
    Last Post: 27th February 2006, 15:37
  4. simple question on Class-Members
    By mickey in forum General Programming
    Replies: 7
    Last Post: 4th February 2006, 22:37
  5. QTextEdit Qt4: simple question
    By TheKedge in forum Qt Programming
    Replies: 4
    Last Post: 18th January 2006, 12:03

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.