LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   .ui.h / kdevelop question (https://www.linuxquestions.org/questions/programming-9/ui-h-kdevelop-question-395714/)

eantoranz 12-22-2005 02:14 PM

.ui.h / kdevelop question
 
I think I got the concept right. I have to use a .ui.h file to make (and code) my own slots. That's OK. But where do I have to code, say a Dialog's constructor? because the .cpp file, and .h and moc.h files are re-created everytime I build the project, so it doesn't make sense to write any code there.

What do you think?

Mara 12-22-2005 02:31 PM

The method most people use (including me) is to write the new class (that inherites the one created in Designer) in a new set of .h and .cpp files (header and implementation). Then you can just #include the orginal header and it can be overwritten by uic without any problems. The rule is: don't modify the files build by automatic tools.

eantoranz 12-26-2005 10:14 AM

OK.... I'm starting to work on that.

I had a UI called "Principal", and I was able to compile it without a problem. I changed its name to PrincipalBase, created a file called principal.h that I will use to extend PrincipalBase, the problem is that I can't build now. :'(

This is the content of principal.h (in case I made a mistake on the extension):

Code:

#include "principalbase.h"

class Principal : public PrincipalBase
{

public:
        Principal();
};

When I build there are a number of messages... saying (among others):
Code:

attention: commands are imposed for the target "principalbase.h"
attention: old instructions are ignored for target "principalbase.h"
circular dependency eliminated principalbase.h <- principalbase.h (3 times in a row)
uic: Failed to parse formas/principal/principalbase.h: unexpected end of file in line 1

After "building" principalbase.h is completely empty.

Any idea of what I'm doing wrong? :scratch:

Mara 12-26-2005 01:44 PM

You need to run 'uic' on the .ui file (clear the project, then build again). Also, make sure that the whole class is renamed, not only the header file.

eantoranz 12-28-2005 08:49 AM

When I start kdevelop, it gets stuck switching between two of the file tabs that I had opened before I closed kdevelop the last time and I can't do anything at all. How can I keep it from happening? :mad:

Mara 12-28-2005 02:53 PM

Your KDevelop config is kept in ~/.kde/share/config/kdevelop3rc. If you delete it, you get the default config.

In your case it may be easier to edit last session. If probect is someproject/ and has someproject/someproject.kdevelop, you need to edit/remove someproject/someproject.kdevses

eantoranz 12-29-2005 08:14 AM

I did something a little less radical. I removed the last doc in the project's .kdevses file. That did the trick.

Will keep you posted about my advances... and Thanks, Mara!

eantoranz 12-30-2005 10:27 AM

I managed (somehow, don't ask :-) ) to extend my original class and make the two QDateEdit fields to have today's date as their date. However, I am starting to miss code completion, and I also had to manually add the .h filed needed as includes (qdatetime.h, qdatetimeedit.h), and that's certainly not the kind of work I want to do (I-m thinking about coing java in eclipse, right now). Is it possible to make kdevelop code-complete as I write? and also that it automagically adds/removes header files as needed?

Mara 12-30-2005 03:14 PM

I'm wondering how you're adding the new classes. Do as much as possible in Designer, the include its' files, they have all the needed includes (usually).

Also, if you have't already, look into Project Options->C++ specific->Code completion You can add your own code completion databases.

eantoranz 12-30-2005 07:20 PM

I extended the hard way. Created two new files: form.h and form.cpp and wrote all the code there. What's the "lazy" way?

Mara 01-01-2006 03:32 PM

'Generate new class' button on on the right side (below 'Open project') or Project->New class

eantoranz 01-02-2006 02:10 PM

Mara, you have been very helpful! I appreciate that! :-)

Do you know how I can build (or maybe install through apt) QT's MySQL Plugin? I'm on a kubuntu breezy box... boxes, as a matter of fact. ;-)

xhi 01-03-2006 12:19 AM

Quote:

Originally Posted by eantoranz
Mara, you have been very helpful! I appreciate that! :-)

Do you know how I can build (or maybe install through apt) QT's MySQL Plugin? I'm on a kubuntu breezy box... boxes, as a matter of fact. ;-)

im not completely sure.. but i think you would have to recompile qt after a configure with
Code:

./configure -plugin-sql-mysql
there may be a way to update the current install.. i dont know of it though..

xhi 01-03-2006 12:22 AM

oops REMOVED same as above..

page not refreshing or even *reacting* when hitting submit.. ??

@moderator.. delete me ???

eantoranz 01-04-2006 09:32 AM

It was a lot simpler than compiling something. There's a package for each driver.

from apt-cache search libqt3:
Code:

libqt3-mt-ibase - InterBase/FireBird database driver for Qt3 (Threaded)
libqt3-mt-mysql - MySQL database driver for Qt3 (Threaded)
libqt3-mt-odbc - ODBC database driver for Qt3 (Threaded)
libqt3-mt-psql - PostgreSQL database driver for Qt3 (Threaded)
libqt3-mt-sqlite - SQLite database driver for Qt3 (Threaded)

In this case:
Code:

apt-get install libqt3-mt-mysql

eantoranz 01-04-2006 02:41 PM

I'm on the Database stuff right now.

What's wrong with this code?

Code:

        QSqlQuery query;
        if (! query.prepare("select * from registro where dominio like ? and hora between ? and ?")) {
                qWarning( "Compilation Failed: " + database->lastError().text() );
                QMessageBox::critical(this, "Error", database->lastError().text(), QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton);
                return slotStop();
        }
        query.bindValue(0, "%" + domain->text() );
        query.bindValue(1, from->date() );
        query.bindValue(2, to->date().addDays(1) );
        if (! query.isActive()) {
                // Problem on the query
                qWarning( "Query Failed: " + database->lastError().text() );
                QMessageBox::critical(this, "Error", database->lastError().text(), QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton);
                return slotStop();
        }

The compilation of the application works fine, however when I run the application the query is not executed (the !isActive() code is executed), but I don't get an error message from the Connection. :scratch:

It's a connection to a MySQL DB.

Mara 01-04-2006 03:44 PM

You don't execute the query, it's only prepared. Add something like:
Code:

if(query.exec () == FALSE) {
    // error
}
//done


eantoranz 01-06-2006 11:58 AM

Mara... you ROCK! Thanks. Let's see how I advance. Will keep you posted. Thank you very much!

eantoranz 01-09-2006 09:52 AM

It's not directly related to kdevelop per se, but to C++, but anyway:

How can I make "correct" use of this:

"There are " + query.size() + " records./n" + " Want to see them anyway?"

The compiler is complaining because I'm mixing: "const char*" with "const char[n]" (being n a given number).

How can I make a single String from that without having to go though a lot of hazzle?

eantoranz 01-09-2006 12:47 PM

how about compiling in windows?
 
How about compiling in windows?

What things do I have to use (should use) to build my kdevelop (basically QT based) project in windows?

If possible, I'd like to go clicking (just like Kdevelop) to build my project. As free an environment as possible (I mean free, beerwise and speechwise). Maybe there's Kdevelop for windows and I haven't heard yet. :-)

I have no IDE / compiler installed on my machine yet.

graemef 01-09-2006 01:18 PM

change

Code:

"There are " + query.size() + " records./n" + " Want to see them anyway?"
to

Code:

"There are " + query.size() + " records./n Want to see them anyway?"

graemef 01-09-2006 01:35 PM

A good C/C++ IDE for windows is DevC++ I've not tried it with QT but it should be possible. However you may need to tweek DevC++ to use the borland bcc compiler since I think that the Windows QT libraries are only compatibel with borland or MSVC.

You can also look at the borland site since I rememeber that they did release an old version of C++ Builder out to the community.

graeme.

Mara 01-09-2006 03:24 PM

Quote:

Originally Posted by eantoranz
What things do I have to use (should use) to build my kdevelop (basically QT based) project in windows?

If it's a qmake-based project, its' just (after you have Qt installed):
qmake -project something.pro
qmake
make
That's all :)

eantoranz 01-10-2006 08:46 AM

Am sorry for my ignorance on C / C++ development on windows:

:scratch: make is provided by windows?

and for graemef: I got the same error message, only with a different n (a bigger one ;-))

graemef 01-10-2006 08:59 AM

Okay are you storing this into a QString? That is what I was expecting...

You will also need to convert the number to a QString...
Code:

QString::number(query.size())
graeme.

eantoranz 01-10-2006 10:03 AM

Let me try.... and about make: I just found out that it's included with MinGW.

Will keep you posted... stay close. :-)

eantoranz 01-10-2006 11:12 AM

I'm trying to compile, but I get this error message:

Code:

qpopupmenu.h: No such file or directory
among 1000 others. I did a search to make sure the file was present, but I didn't find it in my QT installation. I remember that I said not to include QTs source, but I think it said it wasn't necessary if I was going to build QT-based applications. What am I missing?

Maybe it's the version. I'm working with QT3 on linux and I installed QT4.1.0 here on windows... is that the problem?

graemef 01-10-2006 11:50 AM

Most likely you problem is with the different versions (or at least your current problem ;)) QT4 has a very different file layout and the classes are quite different. It doest have access to the old classes but they are names something like Q3BlahBlahBlah.

graeme.

eantoranz 01-10-2006 01:20 PM

As I found no QT3 for windows, I guess I'll have to move up development on linux to QT4. Fortunately this is just a test and I can tweek as much as needed till I "figure it out".

How can I force kdevelop to use qt4? (it's a ubuntu breezy box).

eantoranz 01-10-2006 02:03 PM

Why was I so naive to believe it was going to be so simple? :scratch:

Anyway... I'm just learning that kdevelop will probably use QT4 in their next release... but not right now.

So... what should I do? Try to make windows compile qt3 code or switch to QT4 (working by hand until kdevelop4 is available? :scratch:) altogether?

graemef 01-10-2006 03:13 PM

Hi,

Okay you have just reminded me that QT was not free on Windows prior to release 4. However you can use QT4 on Kdevelop, I think what you need to do is to change the QPATH variable in you bash_profile file. I think that's what I did for Fedora but I'm working on windows today so I can't check :( ...

graeme.

Mara 01-10-2006 03:36 PM

Quote:

Originally Posted by eantoranz
As I found no QT3 for windows, I guess I'll have to move up development on linux to QT4. Fortunately this is just a test and I can tweek as much as needed till I "figure it out".

In fact there is Free QT3 for Windows. It was distributes with Qt book, I don't know how the licence looks now, however (the book is now downloadable).

Quote:

How can I force kdevelop to use qt4? (it's a ubuntu breezy box).
Tricks... If you change PATH in configuration to point first to new executables, you have it done. Also, note that Qt4 has Qt3 compatibility classes (haven't tried them, through).

eantoranz 01-11-2006 07:52 AM

Here's my path:

Code:

$ echo $PATH
/usr/java/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games:/home/antoranz/bin

What should it say instead?

and the other possibility: QPATH. That variable is not set in my environment. What should it be?

graemef 01-11-2006 08:20 AM

Okay I didn't quite get it right, the environment variable is QTDIR...

It's set on my system as:

Quote:

$ echo $QTDIR
/usr/local/Trolltech/Qt-4.1.0
$ echo $PATH
/usr/local/Trolltech/Qt-4.1.0/bin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/usr/local/phing/bin:/home/graeme/bin
Obviously I've QT version 4.1 installed and this is the default path from a standard configure: make: make install.

hope that helps

graeme.

eantoranz 01-11-2006 08:25 AM

Good! But it's not set in my environment either. :-)

eantoranz 01-11-2006 08:26 AM

Perhaps this can help you help me:

Code:

$ dpkg -l qt'*'
Desired=Unknown/Install/Remove/Purge/Hold
| Estado=No/Instalado/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: mayúsc.=malo)
||/ Nombre                  Versión                Descripción
+++-========================-========================-================================================================
un  qt-designer              <ninguna>                (no hay ninguna descripción disponible)
un  qt-designer-doc          <ninguna>                (no hay ninguna descripción disponible)
un  qt-doc                  <ninguna>                (no hay ninguna descripción disponible)
un  qt3-assistant            <ninguna>                (no hay ninguna descripción disponible)
ii  qt3-designer            3.3.4-8ubuntu5          Qt3 Designer
ii  qt3-dev-tools            3.3.4-8ubuntu5          Qt3 development tools
ii  qt3-doc                  3.3.4-8ubuntu5          Qt3 API documentation
un  qt3-linguist            <ninguna>                (no hay ninguna descripción disponible)
un  qt3-qtconfig            <ninguna>                (no hay ninguna descripción disponible)
un  qt3-tools                <ninguna>                (no hay ninguna descripción disponible)
ii  qt4-dev-tools            4.0.0-3ubuntu1          Qt 4 development tools
ii  qt4-doc                  4.0.0-3ubuntu1          Qt 4 API documentation


graemef 01-11-2006 08:59 AM

I don't know where the package will put qt but try a slocate

Code:

$ slocate include/QtCore/QString
hopefully that will help.

graeme.

eantoranz 01-11-2006 12:36 PM

I have /usr/include/qt[34]

inside /usr/include/qt4/ there's QtCore and QtCore/QString

so
Code:

QDIR=/usr/include/qt4/
PATH=$QDIR/bin:$PATH

should do the trick? :-)

eantoranz 01-11-2006 12:43 PM

and about the other problem: I finally made the "String" show up:

Code:

QString("Hay ").append(QString::number(consulta.size())).append(" registros en la consulta. Desea verlos?")
Is there a more elegant way to make it? Or that's the way to go? I'm willing to learn the QT style guide, so to speak. ;-)

eantoranz 01-11-2006 12:58 PM

and bad news (for me, of course). I don't have a bin inside qt4:

Code:

/usr/include/qt4$ find ./ -iname bin'*'
/usr/include/qt4$

That's gonna be a problem, right? :scratch:

I digged a little further:
Code:

$ dpkg -L qt4-dev-tools
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/qt4-dev-tools
/usr/share/doc/qt4-dev-tools/README
/usr/share/doc/qt4-dev-tools/copyright
/usr/share/doc/qt4-dev-tools/changelog.Debian.gz
/usr/share/menu
/usr/share/menu/qt4-dev-tools
/usr/share/qt4
/usr/share/qt4/phrasebooks
/usr/share/qt4/phrasebooks/danish.qph
/usr/share/qt4/phrasebooks/dutch.qph
/usr/share/qt4/phrasebooks/finnish.qph
/usr/share/qt4/phrasebooks/french.qph
/usr/share/qt4/phrasebooks/german.qph
/usr/share/qt4/phrasebooks/italian.qph
/usr/share/qt4/phrasebooks/norwegian.qph
/usr/share/qt4/phrasebooks/russian.qph
/usr/share/qt4/phrasebooks/spanish.qph
/usr/share/qt4/phrasebooks/swedish.qph
/usr/bin
/usr/bin/assistant-qt4
/usr/bin/designer-qt4
/usr/bin/linguist-qt4

If I use update-alternatives I can make assitant-qt4, designer-qt4 and linguist-qt4 the "prefered" qt applications. You think that will be enough to use QT4 by default when using kdevelop? :scratch:

Mara 01-11-2006 04:14 PM

The set is quite short. What you really need (apart from assistant and designer): uic, moc, qmake.

eantoranz 01-12-2006 08:25 AM

after a little 'update-alternatives', I have this:

Code:

$ qmake -v
QMake version: 2.00a
Using Qt version 4.0.0 in /usr/lib
$ moc -v
Qt Meta Object Compiler version 58 (Qt 4.0.0)
$ uic -v
Qt user interface compiler 4.0.0.

What's next? simply call kdevelop3? or there's more tweeking to do?

PS
I just ran kdevelop, my old project, and asked to compile and it says:
QDIR=/usr/share/qt3
and it compiled successfully. I expected it to fail big time. :scratch:

eantoranz 01-12-2006 01:36 PM

qt3 to qt4
 
I thought it was gonna be an easy thing to change from qt3 to qt4, but it seems it isn't just a matter or running the new verion of qmake. I'll have to remake my very first project to see how qt4 works, cause there are many changes.

Will keep you posted. :-) Thanks for your help so far.

PS I'll be working without kdevelop till I figure the whole thing out.

eantoranz 01-13-2006 09:08 AM

some progress on QT4
 
I'm starting to make some progress on QT4, though not working on kdevelop, but kate, designer, konsole and so on. :'(

I have noticed two problems:

When I try to make my project, it doesn't do the uic of the form I'm working on, though I included it in the src.pro file.

Code:

SOURCES += main.cpp
FORMS += formas/principal/principalbase_qt4.ui
TEMPLATE = app
CONFIG += release \
warn_on \
thread \
qt
TARGET = ../bin/squidcalc

Code:

$ qmake src.pro; qmake; make
g++ -c -pipe -O2 -D_REENTRANT -Wall -W -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_GUI_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/default -I. -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtCore -I/usr/include/qt4 -I. -I. -o main.o main.cpp
main.cpp:25:51: error: formas/principal/ui_principalbase_qt4.h: No existe el fichero o el directorio
main.cpp: In function ‘int main(int, char**)’:
main.cpp:35: error: invalid use of undefined type ‘struct QDialog’
/usr/include/qt4/QtGui/qwindowdefs.h:39: error: forward declaration of ‘struct QDialog’
main.cpp:36: error: ‘Ui’ no se puede declarar
main.cpp:36: error: ‘PrincipalBase’ no se declaró en este ámbito
main.cpp:36: error: expected `;' before ‘ui’
main.cpp:37: error: ‘ui’ no se declaró en este ámbito
main.cpp:38: error: invalid use of undefined type ‘struct QDialog’
/usr/include/qt4/QtGui/qwindowdefs.h:39: error: forward declaration of ‘struct QDialog’
make: *** [main.o] Error 1

(by the way, when do I have to run "qmake .profile" or "qmake standalone" or both? :scratch:)

If I uic it myself, going to that directory, then it works:
Code:

$ cd formas/principal/
$ uic principalbase_qt4.ui -o ui_principalbase_qt4.h
$ cd -
$ make
g++ -c -pipe -O2 -D_REENTRANT -Wall -W -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_GUI_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/default -I. -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtCore -I/usr/include/qt4 -I. -I. -o main.o main.cpp
g++  -o ../bin/squidcalc main.o  -L/usr/lib -L/build/buildd/qt4-x11-4.0.0/lib -lQtGui -L/usr/X11R6/lib -laudio -lXt -lpng -lSM -lICE -lXi -lXrender -lXrandr -lXcursor -lXinerama -lfreetype -lXext -lX11 -lm -lQtCore -lfontconfig -lz -ldl -lpthread
$

then I can run the application.

Finally, the second problem: when I run the application, it fails to stop when I close the main form. I have to ctrl+c it.

Here's the main code:
Code:

        QApplication a( argc, argv );
        QDialog *window = new QDialog;
        Ui::PrincipalBase ui;
        ui.setupUi(window);
        window->show();
        a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) );
        return a.exec();

I added the a.connect() as an attempt to make the application close, but it failed too. What am I missing? :scratch:

graemef 01-13-2006 09:16 AM

There is a conversion program from QT3 to QT4. Not certain how accurate it is but worth running your program through that first.

graeme.

eantoranz 01-13-2006 10:00 AM

The form I'm using was already transformed using designer (qt4) and I dropped the qt3 version from the project. The other code I had already made for the project, I'll include it (or should I say twist it) it once I get the naked frame up and running correctly. And thanks for that information. I had alredy read about it on the QT4 help pages.

eantoranz 01-13-2006 01:04 PM

I was able to make it uic the form.

The problem is that I thought it was going to compile formas/principal/formabase_qt4.ui into formas/principal/ui_formabase_qt4.h, and that was my include in main.cpp, but it uics it into ui_formabase_qt4.h (in that same directory of main.cpp). I had to change the include in main.cpp, and then it worked.

Now are there any advices to make the application finish once I close the main frame?

eantoranz 01-16-2006 12:58 PM

OK... I finally made the form show up.

I noticed there was a mistake (i think) in the tutorial that I corrected. The binary ran anyway, but the form showed up with no content. After a while looking at the code, I noticed that the extended class was calling setupUi(this) instead of setupUi(parent). I made the correction and then the frame showed up!

What I'm missing now is the auto-connection. I have two buttons in my form: btnBuscar and btnDetener.

On the extended .h I have:
Code:

#include "ui_principalbase.h"

class Principal: public QDialog, private Ui::PrincipalBase {
        Q_OBJECT

public:
        Principal(QDialog *parent = 0);

private slots:
        void on_btnBuscar_clicked();
        void on_btnDetener_clicked();
};

See I have the two slots.

On the .cpp:
Code:

#include "principal.h"

Principal::Principal(QDialog * parent) : QDialog(parent) {
        setupUi(parent);
}

void Principal::on_btnBuscar_clicked() {
        qWarning("btnBuscar clicked");
}

void Principal::on_btnDetener_clicked() {
        qWarning("btnDetener clicked");
}

See? Very simple and straight forward. Yet when I click on btnBuscar, there's no warning showing up in the console. :'( Is there something I have to do on the .pro file?

And I still have the problem that the application is not finishing after I close the form (the only form). :scratch:

Mara 01-16-2006 03:54 PM

You need to connect the button signal clicked() with your slot.
Code:

connect(btnBuscar, SIGNAL(clicked()), this, SLOT(on_btnBuscar_clicked());
Should be something like that, for each button.

eantoranz 01-16-2006 04:47 PM

Oh, I did that in order to move on... but according to QT4 documentation uic (somehow) can do that work for me automagically. Look QT's autoconnection feature in the QT4 documentation.


All times are GMT -5. The time now is 02:05 AM.