• «
  • 1
  • 2
  • »
  • Pages: 1/2     Go
主题 : 如何用qt2.20 编写多线程程序 十分感谢 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 1083
精华: 0
发帖: 12
金钱: 110 两
威望: 93 点
综合积分: 24 分
注册时间: 2008-07-16
最后登录: 2014-10-12
楼主  发表于: 2009-06-02 16:14

 如何用qt2.20 编写多线程程序 十分感谢

管理提醒: 本帖被 arm9home 从 Linux技术交流专区 移动到本区(2009-09-10)
我编写QT多线程程序,总是报告   错误:expected class-name before ‘{’ token  还有就是说start(),wait()没有定义的错误

请帮忙解决 在此谢过啦

ext16.h文件

#ifndef _DEMO_H_
#define _DEMO_H_

#include <qapplication.h>
#include <qmainwindow.h>
#include <qpopupmenu.h>
#include <qmenubar.h>
#include <qtoolbar.h>
#include <qtoolbutton.h>
#include <qpixmap.h>
#include <qpainter.h>
#include <qmultilineedit.h>
#include <qpushbutton.h>
#include <qscrollview.h>
#include <qfont.h>
#include <qbutton.h>
#include <stdio.h>
#include <qthread.h>
#include <iostream>

class MyThread : public QThread
{
    Q_OBJECT
    public:
        virtual void run();
};

#endif

ext16.cpp文件
#include <ext16.h>

void MyThread::run()
{
   for( int count = 0; count < 20; count++ )
   {
      sleep( 1 );
      qDebug( "Ping!" );
    }
}

int main()
{
  MyThread a;
  MyThread b;
  a.start();
  b.start();
  a.wait();
  b.wait();
}

pro文件
TEMPLATE    = app
CONFIG        = qt warn_on release
HEADERS    = ext16.h
          
SOURCES    = ext16.cpp

INTERFACES    =
TARGET        = hello

bulid文件
#!/bin/bash

source /root/workspace/tools/QT/target-x86/x86-qtopia/qtopia-2.2.0-FriendlyARM/setQpeEnv
qmake -o Makefile -spec /root/workspace/tools/QT/target-x86/x86-qtopia/qtopia-2.2.0-FriendlyARM/qtopia/mkspecs/qws/linux-generic-g++ *.pro  
make clean
make



*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2009-06-02 17:36
复制代码
  1. class MyThread : public QThread
  2. {
  3.     Q_OBJECT
  4.     public:
  5.         virtual void run();
  6. };

这个Q_OBJECT是什么东东?
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 1083
精华: 0
发帖: 12
金钱: 110 两
威望: 93 点
综合积分: 24 分
注册时间: 2008-07-16
最后登录: 2014-10-12
2楼  发表于: 2009-06-02 22:23
只有加入了Q_OBJECT,你才能使用QT中的signal和slot机制。

不加这个QT的一些特有东西就没法用 我这个程序是以前程序复制的 所以加了这个的 我刚才试啦 不加也有错误的

请您帮助我一下 十分感谢的 我主要是想用UART 用线程把UART堵塞在线程里面 可是一直报错的

麻烦啦
级别: 新手上路
UID: 1083
精华: 0
发帖: 12
金钱: 110 两
威望: 93 点
综合积分: 24 分
注册时间: 2008-07-16
最后登录: 2014-10-12
3楼  发表于: 2009-06-02 23:46
那个问题解决拉
现在新的问题出来了
/usr/bin/ld: cannot find -lqte-mt

这个错误  我在makefile添加了thread库 就出这个错误拉 请帮解决一下
级别: 新手上路
UID: 1083
精华: 0
发帖: 12
金钱: 110 两
威望: 93 点
综合积分: 24 分
注册时间: 2008-07-16
最后登录: 2014-10-12
4楼  发表于: 2009-06-03 14:27
我问友善支持 他们说他们不会 谁碰见过请帮助我 十分感谢
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
5楼  发表于: 2009-06-03 15:07
/usr/bin/ld: cannot find -lqte-mt

ld需要找一个叫libqte-mt的库,这个库在友善之臂提供qtopia-2.2.0里并没有提供。你可以重新编译qtopia-2.2.0来获得这个库文件,详细内容看这个http://lists.trolltech.com/qt-interest/2000-11/thread00136-0.html
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 1083
精华: 0
发帖: 12
金钱: 110 两
威望: 93 点
综合积分: 24 分
注册时间: 2008-07-16
最后登录: 2014-10-12
6楼  发表于: 2009-06-03 16:42
这个是其中配置QT的命令
echo yes | ./configure -qte '-embedded -no-xft -qconfig qpe -depths 16,32 -system-jpeg -gif' -qpe '-edition pda -displaysize 240x320  -fontfamilies "helvetica fixed micro smallsmooth smoothtimes"' -qt2 '-no-opengl -no-xft' -dqt '-no-xft -thread'

我再-qte后面加过-thread  可是编译出来还是没有

然后 我分别再 -qte -qt2 -qpe后面加了 然后就报错啦

我打算 在分别 -qt2 -qpe后面加 主要编译时间太长拉

希望加上就没错

还是很感谢 总版主

如果 我说的不对 还请您纠正 在此 十分感谢
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
7楼  发表于: 2009-06-03 16:48
我没有自己改过qt的配置重新编译,不过如果我是的话,我先用./configure --help看看如何加入multi thread(mt)支持
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 1083
精华: 0
发帖: 12
金钱: 110 两
威望: 93 点
综合积分: 24 分
注册时间: 2008-07-16
最后登录: 2014-10-12
8楼  发表于: 2009-06-03 18:32
我还真的没想到 谢谢 哈
这个阶段正是我事业的上升期,我怎么能走得开呢?
级别: 精灵王
UID: 3197
精华: 3
发帖: 770
金钱: 6995 两
威望: 5398 点
综合积分: 1600 分
注册时间: 2008-12-30
最后登录: 2010-12-31
9楼  发表于: 2009-06-03 23:41
如果你的程序不太复杂,根本用不到多线程,目前整个Qtopia-2.2.0里面的示例没有一个是多线程的例子,难道你的应用还能比那些例子复杂?
对Qtopia不熟悉,打开始就用多线程的人大部分是初学者,被Linux基本编程那套给错导了,想想Qtopia是一个多么复杂的系统,但它丝毫没有使用到多线程,它本身的例子就足够你借鉴的。
  • «
  • 1
  • 2
  • »
  • Pages: 1/2     Go