Results 1 to 3 of 3

Thread: Learning Qt with C++

  1. #1
    Join Date
    Apr 2006
    Posts
    40
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Exclamation Learning Qt with C++

    Hello
    I'm a n00b on C++ and Qt I'm working on a Fedora Core 1 with Qt 3.1.2 on the designer
    here I uploaded my app it's a very simple one just for learning... as I must lear to program on c++ and qt as quick as I can for my work.. I'm against the clock and I have almost no time.. as I'm studing too

    well you can download the app HERE with the source code

    My actual problem is filling a QDataTable on Form (the mainForm. the only form realy)
    I'm having some problems as I can't introduce code directly so I made the conection, disconection and qsqlcursor to the database on conexion.cpp and I don't real know how to fill the qdatatable named tabla, on form.ui.h
    help please

    I hope this also help some other n00bs as me
    Battle Programmer Ph1L
    Philip_Anselmo
    Greetings From Osorno - Chile

  2. #2
    Join Date
    Apr 2006
    Posts
    40
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Learning Qt with C++

    The conexion.cpp modified so the QDataTable tabla on the mainwindow Form uses the cursor created on the conexion.cpp is the next code:

    Qt Code:
    1. #include <qsqldatabase.h>
    2. #include <qmessagebox.h>
    3. #include <qdatatable.h>
    4. #include <qsqlcursor.h>
    5. #include "conexion.h"
    6. #include "form.h"
    7.  
    8. QSqlDatabase *defaultDB;
    9. bool creaConexion()
    10. {
    11.  
    12. defaultDB = QSqlDatabase::addDatabase( DBDRIVER );
    13. defaultDB->setDatabaseName( DB_NOM );
    14. defaultDB->setUserName( DB_USR );
    15. defaultDB->setPassword( DB_PASS );
    16. defaultDB->setHostName( DB_HOSTNAME );
    17.  
    18. if ( ! defaultDB->open() ) {
    19. QMessageBox::warning(0, "Fallo de conexión", "No se pudo conectar con la base de datos: " + DB_NOM + "tabla: " + DB_TABLA + "\n" + defaultDB->lastError().driverText());
    20. return FALSE;
    21. }
    22. QMessageBox::information(0,"Conexión estabecida","Conectado a: " + DB_HOSTNAME + " " + "tabla: " + DB_TABLA + " "+ DB_NOM);
    23. return TRUE;
    24. }
    25.  
    26. bool cierraConexion()
    27. {
    28. if (defaultDB->open()){
    29. defaultDB->close();
    30. QMessageBox::information(0,"Cerrando conexión","Desconectando: " + DB_HOSTNAME + " " + DB_NOM);
    31. return TRUE;
    32. }
    33. else{
    34. return FALSE;
    35. }
    36. }
    37.  
    38. void llena()
    39. {
    40. qWarning("Inicio del poblado....");
    41. QSqlCursor cursor( DB_TABLA ); // Especifica la tabla
    42. qWarning("Cursor creado apuntando a la tabla" + DB_TABLA);
    43. cursor.select(); // Devuelve todos los registros de la tabla
    44. qWarning("Cursor llenado ");
    45. while ( cursor.next() ) {}
    46. Form().tabla( &cursor );
    47. }
    To copy to clipboard, switch view to plain text mode 

    as you could tell on first view.. the last line won't work because it treats the tabla widget it were a function, but I guess it isn't because the compiler shows an error on that..
    but on one of th exaples provided by QT 3.1.2 the sqltable to be more specific.. it inicialices the datatable as this:

    Qt Code:
    1. QDataTable tabla( &cursor ); /* data table uses our cursor */
    To copy to clipboard, switch view to plain text mode 

    So I thought (and I guess theres the error xD), that if the widget was already created I maybe could force it to use my cursor from conexion.cpp on the Form.... and then I could fill the... f*** table... help plz

    I'm already out of ideas
    Battle Programmer Ph1L
    Philip_Anselmo
    Greetings From Osorno - Chile

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

    Default Re: Learning Qt with C++

    Download this book: http://www.phptr.com/title/0131240722 and read (at least) chapter 12.

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

    Philip_Anselmo (4th May 2006)

Similar Threads

  1. Learning more about styles
    By bruccutler in forum Newbie
    Replies: 4
    Last Post: 20th February 2010, 09:09
  2. Getting started learning network programming
    By as001622 in forum Qt Programming
    Replies: 1
    Last Post: 20th June 2008, 13:02
  3. Learning by doing
    By skoegl in forum General Discussion
    Replies: 2
    Last Post: 3rd November 2007, 14:18
  4. Learning 2D Graphics
    By ShaChris23 in forum Qt Programming
    Replies: 4
    Last Post: 23rd October 2007, 14:12

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.