Link to home
Start Free TrialLog in
Avatar of lwdalton3
lwdalton3Flag for United States of America

asked on

Where to retrieve in main (c++) what is entered into a qt gui form

With QT3 available with Fedora I have a simple aspiration. I would like to enter into a lineedit widget a file name (a cstring) and have my C++ program go from there and do lots of neat stuff with processing the file. The latter has been pretty much accomplished. Back to Qt3-- I have figured out how to build a form with a textlabel, a lineedit, and a pushbutton. Three simple things easily accomplished in RealBasic, but amazingly less than obvious for QT. Still I would like to give Qt a shot, given open platform, and GNU etc etc

However I cannot figure out where what is entered into the lineedit box ends up. The form is called from main, but I cannot see that anything is returnd to main, and if so where is it? Is it hidden somewhere in a pointer to memory that was allocated by new? If so where is the pointer? I can't see that any pointer is initialized in main that would then have a cstring placed therein. Maybe the memory is allocated in some far off function but I don't see that a pointer is returned. Where is what is entered into the form available in main? Maybe Qt is limited to only the pro's, but any help is appreciated.

And, if so my alternative question is how could I call my C++ program from RealBasic. RealBasic does a fairly decent job in my opinion of making their GUI interface understandable, but I can't find in their documentation the procedure for passing parameters to a C++ plug in. Any help on this will be appreciated as well (only if my Qt question is beyond easy answer). Again I am somewhat trying to avoid realBasic because it appears to be too proprietary (and Visual C)

Thanks in advance LD
Avatar of Duncan Roe
Duncan Roe
Flag of Australia image

Can you post your program? That would make answering iyour Q a lot easier
Avatar of lwdalton3

ASKER

Indeed. Below perhaps explains better. I am sure it is very simple for afficianados of Qt. The difficulty is in the explanation to me. BTW I was able to show the form-- figured out qmake etc


#include <qapplication.h>
#include "form1.h"
#include <cstdlib>
#include <iostream>

using namespace std;

int main( int argc, char ** argv )
{
  QApplication a( argc, argv );
    Form1 w;
      w.show();
    a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
   
      // can I get what is entered into form here and place in a cstring?
                   // i.e.  char *p;
                  // p = something from somewhere

                  // foo -- here is where I wish to place the code that I have already written that works.
                 // I want to get a filename from a qt form, then hit go and the file is processed
                 // I have a program for processing spreadsheet data

return a.exec();
}

the below is the header file generated by qt

/****************************************************************************
** Form interface generated from reading ui file 'form1.ui'
**
** Created by: The User Interface Compiler ($Id: qt/main.cpp   3.3.8   edited Jan 11 14:47 $)
**
** WARNING! All changes made in this file will be lost!
****************************************************************************/

#ifndef FORM1_H
#define FORM1_H
#include <qvariant.h>
#include <qdialog.h>
class QVBoxLayout;
class QHBoxLayout;
class QGridLayout;
class QSpacerItem;
class QLabel;
class QPushButton;
class QLineEdit;
class Form1 : public QDialog
{
    Q_OBJECT
public:
    Form1( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
    ~Form1();
    QLabel* textLabel1;
    QPushButton* pushButton1;
    QLineEdit* lineEdit1;
protected:
protected slots:
    virtual void languageChange();
};
#endif // FORM1_H
Tried to compile your source but without success (see box) (I called your source "myapp.cc")
I suspect there must be another file you need to give me: form1.cc (or dot cxx or cpp)? Or anyway some other file - please check your source directory. Maybe I need the ui file - this is my first compile of a Qt application outside of re-configuring Linux. Don't worry - I expect to be able to answer your Q nevertheless. Just looking at the c++ code, I rather expect we'll end up noting the return from a.exec(), getting out if the return is bad, else accessing members of a.
Not shown in the box: I tweaked the Makefile, replacing "-g" with "-g3 -ggdb" to get extra debug information. But when make failed, I regenerated Makefile without that tweak, just to be sure.
By the way, if in EE you can see a check-box labeled "Attach Code Snippet", you can click that and place the missing files in a box like the one below
18:04:12$ cat myapp.pro
SOURCES = myapp.cc
HEADERS = form1.h
CONFIG += qt warn_on debug
18:06:30$ qmake -o Makefile myapp.pro 
18:06:43$ make
g++ -c -pipe -Wall -W -g  -DQT_SHARED -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -I/usr/lib64/qt-3.3/mkspecs/default -I. -I/usr/lib64/qt-3.3/include -o myapp.o myapp.cc
/usr/lib64/qt-3.3/bin/moc form1.h -o moc_form1.cpp
g++ -c -pipe -Wall -W -g  -DQT_SHARED -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -I/usr/lib64/qt-3.3/mkspecs/default -I. -I/usr/lib64/qt-3.3/include -o moc_form1.o moc_form1.cpp
g++  -o myapp myapp.o moc_form1.o   -L/usr/lib64/qt-3.3/lib -L/usr/X11R6/lib64 -lqt-mt -lXext -lX11 -lm
myapp.o(.text+0x44): In function `main':
/home/dunc/tests/ee16/myapp.cc:11: undefined reference to `Form1::Form1[in-charge](QWidget*, char const*, bool, unsigned)'
myapp.o(.text+0x8b):/home/dunc/tests/ee16/myapp.cc:23: undefined reference to `Form1::~Form1 [in-charge]()'
myapp.o(.text+0xbf):/home/dunc/tests/ee16/myapp.cc:23: undefined reference to `Form1::~Form1 [in-charge]()'
moc_form1.o(.gnu.linkonce.r._ZTV5Form1+0x40):/home/dunc/tests/ee16/moc_form1.cpp:34: undefined reference to `Form1::~Form1 [in-charge]()'
moc_form1.o(.gnu.linkonce.r._ZTV5Form1+0x48):/home/dunc/tests/ee16/moc_form1.cpp:34: undefined reference to `Form1::~Form1 [in-charge deleting]()'
moc_form1.o(.gnu.linkonce.r._ZTV5Form1+0x398): undefined reference to `Form1::languageChange()'
moc_form1.o(.gnu.linkonce.r._ZTV5Form1+0x3b0): undefined reference to `non-virtual thunk [nv:-80] to Form1::~Form1 [in-charge]()'
moc_form1.o(.gnu.linkonce.r._ZTV5Form1+0x3b8): undefined reference to `non-virtual thunk [nv:-80] to Form1::~Form1 [in-charge deleting]()'
collect2: ld returned 1 exit status
make: *** [myapp] Error 1

Open in new window

Thanks. I am using Linux, and EE won't allow adding .o files, or ui, or .h, or .cpp. And to run it seems that qt needs an entire folder for each application with multiple separate files. So below are all the folder files except the object files generated. The below did run under Linux. Maybe all I need is where in the multiple files the lineedit input cstring is returned or placed. From there I can probably insert much of my code  - within a class function instead of main. I highlighted the separate files with   //************ whatever.xxx below

Thanks for continuing to try. LD

//************************main.cpp below

#include <qapplication.h>
#include "form1.h"
#include <cstdlib>
#include <iostream>

using namespace std;

int main( int argc, char ** argv )
{
   
   
   
    QApplication a( argc, argv );
    Form1 w;
     
    w.show();
    a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
    cout <<  "here  is where I want to receive an input cstring" << endl;
    return a.exec();
}

//*************    form1.cpp is below

/****************************************************************************
** Form implementation generated from reading ui file 'form1.ui'
**
** Created by: The User Interface Compiler ($Id: qt/main.cpp   3.3.8   edited Jan 11 14:47 $)
**
** WARNING! All changes made in this file will be lost!
****************************************************************************/

#include "form1.h"

#include <qvariant.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qlineedit.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qimage.h>
#include <qpixmap.h>

/*
 *  Constructs a Form1 as a child of 'parent', with the
 *  name 'name' and widget flags set to 'f'.
 *
 *  The dialog will by default be modeless, unless you set 'modal' to
 *  TRUE to construct a modal dialog.
 */
Form1::Form1( QWidget* parent, const char* name, bool modal, WFlags fl )
    : QDialog( parent, name, modal, fl )
{
    if ( !name )
      setName( "Form1" );

    textLabel1 = new QLabel( this, "textLabel1" );
    textLabel1->setGeometry( QRect( 20, 50, 191, 31 ) );

    pushButton1 = new QPushButton( this, "pushButton1" );
    pushButton1->setEnabled( TRUE );
    pushButton1->setGeometry( QRect( 20, 190, 131, 60 ) );
    QFont pushButton1_font(  pushButton1->font() );
    pushButton1_font.setBold( TRUE );
    pushButton1->setFont( pushButton1_font );
    pushButton1->setToggleButton( TRUE );
    pushButton1->setOn( TRUE );

    lineEdit1 = new QLineEdit( this, "lineEdit1" );
    lineEdit1->setGeometry( QRect( 30, 120, 241, 31 ) );
    languageChange();
    resize( QSize(301, 286).expandedTo(minimumSizeHint()) );
    clearWState( WState_Polished );
}

/*
 *  Destroys the object and frees any allocated resources
 */
Form1::~Form1()
{
    // no need to delete child widgets, Qt does it all for us
}

/*
 *  Sets the strings of the subwidgets using the current
 *  language.
 */
void Form1::languageChange()
{
    setCaption( tr( "Form1" ) );
    textLabel1->setText( tr( "Enter filename" ) );
    pushButton1->setText( tr( "go" ) );
}

//   *****************************form1.h is below

/****************************************************************************
** Form interface generated from reading ui file 'form1.ui'
**
** Created by: The User Interface Compiler ($Id: qt/main.cpp   3.3.8   edited Jan 11 14:47 $)
**
** WARNING! All changes made in this file will be lost!
****************************************************************************/

#ifndef FORM1_H
#define FORM1_H

#include <qvariant.h>
#include <qdialog.h>

class QVBoxLayout;
class QHBoxLayout;
class QGridLayout;
class QSpacerItem;
class QLabel;
class QPushButton;
class QLineEdit;

class Form1 : public QDialog
{
    Q_OBJECT

public:
    Form1( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
    ~Form1();

    QLabel* textLabel1;
    QPushButton* pushButton1;
    QLineEdit* lineEdit1;

protected:

protected slots:
    virtual void languageChange();

};

#endif // FORM1_H

//*************** form1.ui below*********************

<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
<class>Form1</class>
<widget class="QDialog">
    <property name="name">
        <cstring>Form1</cstring>
    </property>
    <property name="geometry">
        <rect>
            <x>0</x>
            <y>0</y>
            <width>301</width>
            <height>286</height>
        </rect>
    </property>
    <property name="caption">
        <string>Form1</string>
    </property>
    <widget class="QLabel">
        <property name="name">
            <cstring>textLabel1</cstring>
        </property>
        <property name="geometry">
            <rect>
                <x>20</x>
                <y>50</y>
                <width>191</width>
                <height>31</height>
            </rect>
        </property>
        <property name="text">
            <string>Enter filename</string>
        </property>
    </widget>
    <widget class="QPushButton">
        <property name="name">
            <cstring>pushButton1</cstring>
        </property>
        <property name="enabled">
            <bool>true</bool>
        </property>
        <property name="geometry">
            <rect>
                <x>20</x>
                <y>190</y>
                <width>131</width>
                <height>60</height>
            </rect>
        </property>
        <property name="font">
            <font>
                <bold>1</bold>
            </font>
        </property>
        <property name="text">
            <string>go</string>
        </property>
        <property name="toggleButton">
            <bool>true</bool>
        </property>
        <property name="on">
            <bool>true</bool>
        </property>
    </widget>
    <widget class="QLineEdit">
        <property name="name">
            <cstring>lineEdit1</cstring>
        </property>
        <property name="geometry">
            <rect>
                <x>30</x>
                <y>120</y>
                <width>241</width>
                <height>31</height>
            </rect>
        </property>
    </widget>
</widget>
<pixmapinproject/>
<layoutdefaults spacing="6" margin="11"/>
</UI>

//  *****************makefile below

#############################################################################
# Makefile for building: yet
# Generated by qmake (1.07a) (Qt 3.3.8) on: Thu Jan 24 07:10:32 2008
# Project:  yet.pro
# Template: app
# Command: $(QMAKE) -o Makefile yet.pro
#############################################################################

####### Compiler, tools and options

CC       = gcc
CXX      = g++
LEX      = flex
YACC     = yacc
CFLAGS   = -pipe -Wall -W -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables  -DQT_NO_DEBUG -DQT_SHARED -DQT_TABLET_SUPPORT -DQT_THREAD_SUPPORT
CXXFLAGS = -pipe -Wall -W -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables  -DQT_NO_DEBUG -DQT_SHARED -DQT_TABLET_SUPPORT -DQT_THREAD_SUPPORT
LEXFLAGS =
YACCFLAGS= -d
INCPATH  = -I/usr/lib/qt-3.3/mkspecs/default -I. -I. -I$(QTDIR)/include
LINK     = g++
LFLAGS   =
LIBS     = $(SUBLIBS) -L$(QTDIR)/lib -lqt-mt -lXext -lX11 -lm
AR       = ar cqs
RANLIB   =
MOC      = $(QTDIR)/bin/moc
UIC      = $(QTDIR)/bin/uic
QMAKE    = qmake
TAR      = tar -cf
GZIP     = gzip -9f
COPY     = cp -f
COPY_FILE= $(COPY)
COPY_DIR = $(COPY) -r
INSTALL_FILE= $(COPY_FILE)
INSTALL_DIR = $(COPY_DIR)
DEL_FILE = rm -f
SYMLINK  = ln -sf
DEL_DIR  = rmdir
MOVE     = mv -f
CHK_DIR_EXISTS= test -d
MKDIR    = mkdir -p

####### Output directory

OBJECTS_DIR = ./

####### Files

HEADERS =
SOURCES = main.cpp
OBJECTS = main.o \
            form1.o
FORMS = form1.ui
UICDECLS = form1.h
UICIMPLS = form1.cpp
SRCMOC   = moc_form1.cpp
OBJMOC = moc_form1.o
DIST         = yet.pro
QMAKE_TARGET = yet
DESTDIR  =
TARGET   = yet

first: all
####### Implicit rules

.SUFFIXES: .c .o .cpp .cc .cxx .C

.cpp.o:
      $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.cc.o:
      $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.cxx.o:
      $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.C.o:
      $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.c.o:
      $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<

####### Build rules

all: Makefile $(TARGET)

$(TARGET):  $(UICDECLS) $(OBJECTS) $(OBJMOC)  
      $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJMOC) $(OBJCOMP) $(LIBS)

mocables: $(SRCMOC)
uicables: $(UICDECLS) $(UICIMPLS)

$(MOC):
      ( cd $(QTDIR)/src/moc && $(MAKE) )

Makefile: yet.pro  /usr/lib/qt-3.3/mkspecs/default/qmake.conf /usr/lib/qt-3.3/lib/libqt-mt.prl
      $(QMAKE) -o Makefile yet.pro
qmake:
      @$(QMAKE) -o Makefile yet.pro

dist:
      @mkdir -p .tmp/yet && $(COPY_FILE) --parents $(SOURCES) $(HEADERS) $(FORMS) $(DIST) .tmp/yet/ && ( cd `dirname .tmp/yet` && $(TAR) yet.tar yet && $(GZIP) yet.tar ) && $(MOVE) `dirname .tmp/yet`/yet.tar.gz . && $(DEL_FILE) -r .tmp/yet

mocclean:
      -$(DEL_FILE) $(OBJMOC)
      -$(DEL_FILE) $(SRCMOC)

uiclean:
      -$(DEL_FILE) $(UICIMPLS) $(UICDECLS)

yaccclean:
lexclean:
clean: mocclean uiclean
      -$(DEL_FILE) $(OBJECTS)
      -$(DEL_FILE) *~ core *.core


####### Sub-libraries

distclean: clean
      -$(DEL_FILE) $(TARGET) $(TARGET)


FORCE:

####### Compile

main.o: main.cpp form1.h

form1.h: form1.ui
      $(UIC) form1.ui -o form1.h

form1.cpp: form1.h form1.ui
      $(UIC) form1.ui -i form1.h -o form1.cpp

form1.o: form1.cpp form1.h

moc_form1.o: moc_form1.cpp  form1.h

moc_form1.cpp: $(MOC) form1.h
      $(MOC) form1.h -o moc_form1.cpp

####### Install

install:  

uninstall:  

//***********************moc_form1.cpp  below **********************

/****************************************************************************
** Form1 meta object code from reading C++ file 'form1.h'
**
** Created: Wed Jan 23 22:20:55 2008
**      by: The Qt MOC ($Id: qt/moc_yacc.cpp   3.3.8   edited Feb 2 14:59 $)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/

#undef QT_NO_COMPAT
#include "form1.h"
#include <qmetaobject.h>
#include <qapplication.h>

#include <private/qucomextra_p.h>
#if !defined(Q_MOC_OUTPUT_REVISION) || (Q_MOC_OUTPUT_REVISION != 26)
#error "This file was generated using the moc from 3.3.8. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif

const char *Form1::className() const
{
    return "Form1";
}

QMetaObject *Form1::metaObj = 0;
static QMetaObjectCleanUp cleanUp_Form1( "Form1", &Form1::staticMetaObject );

#ifndef QT_NO_TRANSLATION
QString Form1::tr( const char *s, const char *c )
{
    if ( qApp )
      return qApp->translate( "Form1", s, c, QApplication::DefaultCodec );
    else
      return QString::fromLatin1( s );
}
#ifndef QT_NO_TRANSLATION_UTF8
QString Form1::trUtf8( const char *s, const char *c )
{
    if ( qApp )
      return qApp->translate( "Form1", s, c, QApplication::UnicodeUTF8 );
    else
      return QString::fromUtf8( s );
}
#endif // QT_NO_TRANSLATION_UTF8

#endif // QT_NO_TRANSLATION

QMetaObject* Form1::staticMetaObject()
{
    if ( metaObj )
      return metaObj;
    QMetaObject* parentObject = QDialog::staticMetaObject();
    static const QUMethod slot_0 = {"languageChange", 0, 0 };
    static const QMetaData slot_tbl[] = {
      { "languageChange()", &slot_0, QMetaData::Protected }
    };
    metaObj = QMetaObject::new_metaobject(
      "Form1", parentObject,
      slot_tbl, 1,
      0, 0,
#ifndef QT_NO_PROPERTIES
      0, 0,
      0, 0,
#endif // QT_NO_PROPERTIES
      0, 0 );
    cleanUp_Form1.setMetaObject( metaObj );
    return metaObj;
}

void* Form1::qt_cast( const char* clname )
{
    if ( !qstrcmp( clname, "Form1" ) )
      return this;
    return QDialog::qt_cast( clname );
}

bool Form1::qt_invoke( int _id, QUObject* _o )
{
    switch ( _id - staticMetaObject()->slotOffset() ) {
    case 0: languageChange(); break;
    default:
      return QDialog::qt_invoke( _id, _o );
    }
    return TRUE;
}

bool Form1::qt_emit( int _id, QUObject* _o )
{
    return QDialog::qt_emit(_id,_o);
}
#ifndef QT_NO_PROPERTIES

bool Form1::qt_property( int id, int f, QVariant* v)
{
    return QDialog::qt_property( id, f, v);
}

bool Form1::qt_static_property( QObject* , int , int , QVariant* ){ return FALSE; }
#endif // QT_NO_PROPERTIES

//******* file called  yet.pro   the application is stored in folder called "yet" ****

######################################################################
# Automatically generated by qmake (1.07a) Thu Jan 24 07:10:27 2008
######################################################################

TEMPLATE = app
INCLUDEPATH += .

# Input
INTERFACES += form1.ui
SOURCES += main.cpp

I think your immediate problem is that the form needs to be designed differently. A modal form needs to have at least one control that causes the form to disappear and return a result. Your Go button doesn't do that. I can press the X in the window title bar which closes the window and causes a return (with code 0) - you should really Have a Cancel button to do that. As well you need an OK button - presumably you meant Go to be that but it's not functioning as such.
I'd have to get properly into Qt to help you further which I might try to do. The .ui file is produced by some kind of form designer isn't it? Can you give me some pointers re what you configured?
There seems to be plenty of documentation so I'll give it a try. No promises though
Got slightly distracted today by deciding to rebuild Qt for x86_64, starting from a 32-bit build. Original rpm install didn't have man pages. Took me forever to find the "-platform" argument to configure, but it's installed now.
From initial reading of the documentation, it seems your main() is OK - you are missing signals and slots. That seems to be how the form communicates GUI actions to user code.
Thanks for your continuing effort. I was out as well. The Qt documentation I have seen, starts real easy, and then steps to advanced without any middle ground where hobbyists as myself reside. The documentation tells how to build a form, and how to compile using qmake, but not where to place custom code. Let me play with a few of the suggestions above as I have some ideas and allow me to possibly narrow the question a bit futher. The ui is indeed automatically built by qt with qmake. The form is designed within qt designer. Then qmake is run. The only code to write by hand is main, and so since all the other code is automatically generated it is difficult to discover where things might be plugged in. It is not like RealBasic where you double click on a push button and write code behind it. But then maybe I have the wrong pushbutton and so based on your comment I will look into that.

Thanks Les
I started at file:///usr/lib/qt/doc/html/index.html. From there I selected "How to Learn Qt". I downloaded the white paper from http://www.trolltech.com/products/qt/whitepaper.html and am reading through that - it seems to document signals and slots reasonably. Amaxzon are sold out of the book right now.
Ok, I think I've got it. Myapp.cc is amended to connect the click() event generated by the Go button to a handler. The handler prints that the button was clicked, and also the current value of the linedit box. Myapp.cc creates the handler object, passing in the form so that the handler can access form members. The amended and new files are in the box
================AMENDED
21:59:41$ cat myapp.pro
SOURCES = myapp.cc printlabel.cc form1.cc
HEADERS = form1.h printlabel.h
CONFIG += qt warn_on debug
 
================AMENDED
yapp.cc
#include <qapplication.h>
#include "form1.h"
#include <cstdlib>
#include <iostream>
#include "printlabel.h"
 
using namespace std;
 
int
main(int argc, char **argv)
{
 
  QApplication a(argc, argv);
  Form1 w;
  w.show();
  a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
  
  // Set up a connection to the Go button
  PrintLabel *p = new PrintLabel(&w);
  a.connect((QObject*)w.pushButton1, SIGNAL(clicked()), p, SLOT(Clicked()));
  return a.exec();
}
 
================NEW
22:01:17$ cat printlabel.h 
#ifndef PRINTLABEL_H
#define PRINTLABEL_H
#include <qobject.h>
#include "form1.h"
class PrintLabel : public QObject
{
  private:
    Q_OBJECT
    Form1 *myform;
  public:
    PrintLabel(Form1 *);
    ~PrintLabel();
  public slots:
    void Clicked();
};                                 /* class PrintLabel : QObject */
 
#endif
 
================NEW
22:03:31$ cat printlabel.cc
#include <qapplication.h>
#include "form1.h"
#include <cstdlib>
#include <iostream>
#include "printlabel.h"
#include <qlineedit.h>
 
using namespace std;
 
PrintLabel::PrintLabel(Form1 *w)
{
  myform = w;
}
PrintLabel::~PrintLabel() {}
void PrintLabel::Clicked()
{
  printf("Got a click\n");
  printf("Label text is \"%s\"\n", myform->lineEdit1->text().ascii());
}                                  /* PrintLabel::Clicked() */

Open in new window

The line "yapp.cc" should read "21:59:48$ cat myapp.cc". I had to cast w.pushButton1 to QObject* to keep the compiler happy - no real idea why, but it did the job.
ASKER CERTIFIED SOLUTION
Avatar of Duncan Roe
Duncan Roe
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Qt is hard, and anyone trying to explain in this type of forum is going to have a rough row to hoe. It would be nice if Trolltech had a hobbyist edition. Anyhow what finally helped me is that a slot is a function, and main doesn't do much. Thanks for an obvious effort on my behalf and hopefully my next question will be more straightforward. Cheers LD