Results 1 to 4 of 4

Thread: Need some help porting from Qt3 to Qt4

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2008
    Posts
    9
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Need some help


    Hi


    I am new to the Qt environment.i am developing an application in Qt 4.4 under windows platform.i want my application to run when my system reboots or restarts.for this i have to load my application(.exe or .ini files) into windows registry.can i have some code snippets for this.

    Thanks & regards,
    Srikanthch
    srikanthc49@gmail.com

  2. #2
    Join Date
    Nov 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Need some help porting from Qt3 to Qt4

    Thanks jacek
    I was trying an approach whereby I will use QImage [cannot use QPixmap as I guess painting into QPixmap is not allowed from nonGUI thread] as my offscreen buffer and tried painting into that and in paintEvent trying to flush QImage into the Qt window.
    Do you think this approach will work?

    I am attaching the native application I tried to modify to use this approach
    Qt Code:
    1. #include <pthread.h>
    2. #include <Qt>
    3. #include <QtCore>
    4. #include <QtGui>
    5.  
    6. #include <QPainter>
    7. #include <QWidget>
    8. #include <QImage>
    9.  
    10. class QPen;
    11. class QBrush;
    12. class QImage;
    13.  
    14. #define qtApp ((QtApplication *)qApp)
    15. void threadfunc(void *arg);
    16. void AWT_drawline(int x1, int y1, int x2, int y2);
    17. void getQtColorModel();
    18. void Qtexec();
    19.  
    20.  
    21. QImage img(800,600,QImage::Format_ARGB32);
    22.  
    23. class QtWindow : public QWidget
    24. {
    25. QBitmap transMask;
    26.  
    27. public:
    28. QtWindow(int flags,
    29. const char *name = "Sun AWT/Qt",
    30. QWidget *parent = NULL) ;
    31. virtual void paintEvent(QPaintEvent *);
    32.  
    33. };
    34.  
    35. class QtApplication : public QApplication {
    36. public :
    37. QtApplication(int &argc, char **argv);
    38. int exec(); //overloadded exec from QApplication
    39. };
    40.  
    41. class QtScreen
    42. {
    43. protected :
    44. int m_x;
    45. int m_y;
    46. int m_width;
    47. int m_height;
    48. QtWindow *m_window;
    49. bool m_bounds_restricted;
    50. /* virtual char **getArgs(int *argc);
    51.   virtual void computeBounds();
    52.   virtual void createQtWindow();
    53.   virtual void windowShown();
    54. */
    55.  
    56. public :
    57. QtScreen();
    58. bool init();
    59. /* void close();
    60.   void showWindow();
    61.   void setMouseCursor(int cursor);
    62.   void beep();
    63.   int width();
    64.   int height();
    65.   int dotsPerInch();
    66.   QtWindow *window();
    67.   int x();
    68.   int y();
    69. */
    70. };
    71.  
    72. class QtScreenFactory
    73. {
    74. static QtScreen *theScreen;
    75. public:
    76. static QtScreen *getScreen();
    77. };
    78.  
    79.  
    80. QtWindow *m_window;
    81. QtScreen *QtScreenFactory::theScreen = NULL;
    82. QtApplication::QtApplication(int &argc, char **argv) : QApplication(argc, argv) {
    83. }
    84.  
    85. int
    86. QtApplication::exec(void) {
    87. printf("QApplication exec called\n");
    88. QApplication::exec();
    89. printf("QApplication exec done\n");
    90. }
    91.  
    92. QtWindow::QtWindow(int flags, const char *name, QWidget *parent) :
    93. QWidget(parent, (Qt::WindowFlags)flags)
    94. {
    95. setMouseTracking(true);
    96. }
    97.  
    98. void
    99. QtWindow::paintEvent(QPaintEvent *event)
    100. {
    101. printf("paintEvent called\n");
    102. #if 0
    103. QPen *qp = new QPen();
    104. QColor c(0xffff0000);
    105. qp->setColor(c);
    106. QBrush *qb = new QBrush();
    107. QPainter p(this);
    108. p.setCompositionMode(QPainter::CompositionMode_SourceOver);
    109. p.setPen(*qp);
    110. p.setClipRect(0,0,800,600);
    111. p.drawLine(30,135,790,135);
    112. #endif
    113. QPainter p(m_window);
    114. QPoint pt(0,0);
    115. p.drawImage(pt, img);
    116. }
    117.  
    118. int main(int argc, char **argv)
    119. {
    120. printf("argc %d, argv %s\n",argc, *argv);
    121. QtScreen *screen = QtScreenFactory::getScreen();
    122. // img = new QImage(800,600,QImage::Format_ARGB32);
    123. }
    124.  
    125. QtScreen *
    126. QtScreenFactory::getScreen() {
    127. if ( QtScreenFactory::theScreen == NULL ) {
    128. QtScreenFactory::theScreen = new QtScreen();
    129. if(QtScreenFactory::theScreen != NULL) {
    130. QtScreenFactory::theScreen->init();
    131. }
    132. }
    133. return QtScreenFactory::theScreen;
    134. }
    135.  
    136. QtScreen::QtScreen()
    137. {
    138. }
    139.  
    140. void getQtColorModel()
    141. {
    142. int depth = 0;
    143. int amask=0,rmask=0,gmask=0,bmask=0;
    144.  
    145. QWidget *d = QApplication::desktop();
    146. depth = d->depth();
    147. printf ("Depth = %d\n", depth);
    148. switch(depth) {
    149. case 32:
    150. amask = 0xff000000;
    151. case 24:
    152. rmask = 0x00ff0000;
    153. gmask = 0x0000ff00;
    154. bmask = 0x000000ff;
    155. break;
    156. }
    157. }
    158.  
    159. void Qtexec()
    160. {
    161. qtApp->exec();
    162. }
    163.  
    164. bool
    165. QtScreen::init()
    166. {
    167. pthread_t tid;
    168. int m_x = 0,m_y=0,m_width=800,m_height=600;
    169.  
    170. int argc = 1;
    171. char *argv[3] = {"a.out", "-qws", NULL};
    172. new QtApplication(argc, argv);
    173. m_window = new QtWindow(Qt::FramelessWindowHint|Qt::Window);
    174. QBitmap bitmap(m_width, m_height);
    175. qtApp->setActiveWindow(m_window);
    176.  
    177. QPaintDevice *qpd = m_window;
    178. printf("exec called\n");
    179. m_window->show();
    180. getQtColorModel();
    181. #if 1
    182. pthread_create(&tid, NULL, (void *(*)(void *))threadfunc, NULL);
    183. #endif
    184. Qtexec();
    185. }
    186.  
    187.  
    188. void threadfunc(void *arg)
    189. {
    190. printf("threadfunc called\n");
    191. AWT_drawline(30,135,790,135);
    192. }
    193.  
    194. void
    195. AWT_drawline(int x1, int y1, int x2, int y2)
    196. {
    197. #if 0
    198. QPen *qp = new QPen();
    199. QBrush *qb = new QBrush();
    200. QPainter p(qpd);
    201. p.setCompositionMode(QPainter::CompositionMode_SourceOver);
    202. p.setPen(*qp);
    203. p.setClipRect(0,0,800,600);
    204. p.drawLine(30,135,790,135);
    205. #endif
    206. QPainter p(&img);
    207. p.setCompositionMode(QPainter::CompositionMode_SourceOver);
    208. QPen *qp = new QPen();
    209. QColor c(0xffff0000);
    210. qp->setColor(c);
    211. QBrush *qb = new QBrush();
    212. p.setPen(*qp);
    213. p.setClipRect(0,0,800,600);
    214. p.drawLine(x1, y1, x2, y2);
    215. m_window->update(0,0,800,600);
    216. }
    To copy to clipboard, switch view to plain text mode 

    But while executing this, I got a segv
    (gdb) run
    Starting program: /export/WorkSpaces/a.out
    [Thread debugging using libthread_db enabled]
    [New Thread -1208498480 (LWP 3723)]
    argc 1, argv /export/WorkSpaces/a.out
    Qt: gdb: -nograb added to command-line options.
    Use the -dograb option to enforce grabbing.
    exec called
    Depth = 24
    [New Thread -1212621936 (LWP 3727)]
    QApplication exec called
    threadfunc called

    Program received signal SIGSEGV, Segmentation fault.
    [Switching to Thread -1212621936 (LWP 3727)]
    0x0077021d in QWidget::testAttribute (this=0x0,
    attribute=Qt::WA_WState_Visible)
    at ../../include/QtGui/../../src/gui/kernel/qwidget.h:986
    986 return data->widget_attributes & (1<<attribute);
    (gdb) bt
    #0 0x0077021d in QWidget::testAttribute (this=0x0,
    attribute=Qt::WA_WState_Visible)
    at ../../include/QtGui/../../src/gui/kernel/qwidget.h:986
    #1 0x007702e3 in QWidget::isVisible (this=0x0)
    at ../../include/QtGui/../../src/gui/kernel/qwidget.h:948
    #2 0x009632ee in QWidget::update (this=0x0, r=@0xb7b8d338)
    at painting/qbackingstore.cpp:1203
    #3 0x0804b2d7 in QWidget::update (this=0x0, ax=0, ay=0, aw=800, ah=600)
    at /usr/local/Trolltech/QtDebug-4.4.3/include/QtGui/qwidget.h:945
    #4 0x0804a8bb in AWT_drawline (x1=30, y1=135, x2=790, y2=135)
    at drawline.cpp:214
    #5 0x0804a924 in threadfunc (arg=0x0) at drawline.cpp:190
    #6 0x0050044b in start_thread () from /lib/libpthread.so.0
    #7 0x0047780e in clone () from /lib/libc.so.6
    (gdb)

    Can you please tell me as to what might be wrong in the application?

    If you feel this is not the right approach, then can you please tell me how to use the event-driven approach. Which class to use and how in the above appln.?

    Thanks in advance

Similar Threads

  1. Porting from qwt-4.2.0 to qwt-5.0.2
    By vheinitz in forum Qwt
    Replies: 3
    Last Post: 31st January 2008, 12:39
  2. Common question about porting Qt3 to Qt4
    By zlatko in forum Qt Programming
    Replies: 4
    Last Post: 21st February 2007, 10:57
  3. Problem porting Kivio MP on win32 from Qt 3 to Qt 4
    By Amanda in forum Qt Programming
    Replies: 2
    Last Post: 26th October 2006, 19:40
  4. Porting QT3 or 4
    By antonyang in forum Newbie
    Replies: 1
    Last Post: 3rd October 2006, 16:57
  5. Problem in porting Main window on linux
    By jyoti kumar in forum Qt Tools
    Replies: 2
    Last Post: 2nd June 2006, 08:35

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
  •  
Qt is a trademark of The Qt Company.