MAIN.cpp
#include <qapplication.h>
#include "messenger.h"
int main( int argc, char *argv[])
{
QApplication app(argc, argv);
Messenger *messenger= new Messenger;
app.setMainWidget(messenger);
messenger->show();
return app.exec();
}
FRENCH.H
#ifndef FRENCH_H
#define FRENCH_H
#include <qthread.h>
#include <qtextedit.h>
#include "form1.h"
class OtherThread: public QThread
{
public:
OtherThread(QTextEdit *text2);
void run();
bool one_after_two;
QTextEdit *tEdit2;
protected:
void sleep(unsigned long secs );
};
#endif
FRENCH.CPP
#include "french.h"
#include <qmutex.h>
OtherThread::OtherThread(QTextEdit *text2)
{
tEdit2=text2;
}
void OtherThread::run()
{
QMutex *mute = new QMutex();
mute->lock();
for(int tt=0; tt<250;tt++)
{
tEdit2->append("hurricane");
}
mute->unlock();
}
MESSENGER.H
#ifndef MESSENGER_H
#define MESSENGER_H
#include "form1.h"
#include "french.h"
class Messenger: public Form1
{
Q_OBJECT
public:
OtherThread *thr;
Messenger(QWidget *parent=0, const char *name=0);
~Messenger();
void Send_Mes();
public slots:
void sending();
};
#endif
MESSENGER.CPP
#include "messenger.h"
Messenger::Messenger(QWidget *parent, const char *name)
{
Send_Mes();
}
Messenger::~Messenger()
{
}
void Messenger::Send_Mes()
{
connect(Send_but, SIGNAL(clicked()), this, SLOT(sending()));
}
void Messenger::sending()
{
thr =new OtherThread(textEdit2);
//Sleep(1200);
thr->start();
}
form1.ui
[size=7]<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
<class>Form1</class>
<widget class="QWidget">
<property name="name">
<cstring>Form1</cstring>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>271</width>
<height>196</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>1</hsizetype>
<vsizetype>1</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="paletteForegroundColor">
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</property>
<property name="paletteBackgroundColor">
<color>
<red>218</red>
<green>231</green>
<blue>250</blue>
</color>
</property>
<property name="palette">
<palette>
<active>
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
<color>
<red>127</red>
<green>168</green>
<blue>168</blue>
</color>
<color>
<red>191</red>
<green>252</green>
<blue>252</blue>
</color>
<color>
<red>159</red>
<green>210</green>
<blue>210</blue>
</color>
<color>
<red>64</red>
<green>84</green>
<blue>84</blue>
</color>
<color>
<red>85</red>
<green>112</green>
<blue>112</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
<color>
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
<color>
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
<color>
<red>218</red>
<green>231</green>
<blue>250</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>128</blue>
</color>
<color>
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</active>
<disabled>
<color>
<red>128</red>
<green>128</green>
<blue>128</blue>
</color>
<color>
<red>127</red>
<green>168</green>
<blue>168</blue>
</color>
<color>
<red>191</red>
<green>252</green>
<blue>252</blue>
</color>
<color>
<red>146</red>
<green>193</green>
<blue>193</blue>
</color>
<color>
<red>64</red>
<green>84</green>
<blue>84</blue>
</color>
<color>
<red>85</red>
<green>112</green>
<blue>112</blue>
</color>
<color>
<red>128</red>
<green>128</green>
<blue>128</blue>
</color>
<color>
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
<color>
<red>128</red>
<green>128</green>
<blue>128</blue>
</color>
<color>
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
<color>
<red>218</red>
<green>231</green>
<blue>250</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>128</blue>
</color>
<color>
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>255</blue>
</color>
<color>
<red>255</red>
<green>0</green>
<blue>255</blue>
</color>
</disabled>
<inactive>
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
<color>
<red>127</red>
<green>168</green>
<blue>168</blue>
</color>
<color>
<red>191</red>
<green>252</green>
<blue>252</blue>
</color>
<color>
<red>146</red>
<green>193</green>
<blue>193</blue>
</color>
<color>
<red>64</red>
<green>84</green>
<blue>84</blue>
</color>
<color>
<red>85</red>
<green>112</green>
<blue>112</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
<color>
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
<color>
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
<color>
<red>218</red>
<green>231</green>
<blue>250</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>128</blue>
</color>
<color>
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>255</blue>
</color>
<color>
<red>255</red>
<green>0</green>
<blue>255</blue>
</color>
</inactive>
</palette>
</property>
<property name="caption">
<string>Send</string>
</property>
<widget class="QTextEdit">
<property name="name">
<cstring>textEdit3</cstring>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>10</y>
<width>88</width>
<height>60</height>
</rect>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>Cancel_but</cstring>
</property>
<property name="geometry">
<rect>
<x>191</x>
<y>126</y>
<width>50</width>
<height>24</height>
</rect>
</property>
<property name="paletteBackgroundColor">
<color>
<red>208</red>
<green>217</green>
<blue>255</blue>
</color>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>Clear_but</cstring>
</property>
<property name="geometry">
<rect>
<x>191</x>
<y>96</y>
<width>50</width>
<height>24</height>
</rect>
</property>
<property name="paletteBackgroundColor">
<color>
<red>208</red>
<green>217</green>
<blue>255</blue>
</color>
</property>
<property name="text">
<string>Clear</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>Reply_but</cstring>
</property>
<property name="geometry">
<rect>
<x>14</x>
<y>167</y>
<width>80</width>
<height>24</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>7</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="paletteBackgroundColor">
<color>
<red>208</red>
<green>217</green>
<blue>255</blue>
</color>
</property>
<property name="text">
<string>Reply</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>Send_but</cstring>
</property>
<property name="geometry">
<rect>
<x>160</x>
<y>167</y>
<width>80</width>
<height>24</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>7</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="paletteBackgroundColor">
<color>
<red>208</red>
<green>217</green>
<blue>255</blue>
</color>
</property>
<property name="text">
<string>Send</string>
</property>
</widget>
<widget class="QTextEdit">
<property name="name">
<cstring>textEdit1</cstring>
</property>
<property name="geometry">
<rect>
<x>10</x>
<y>90</y>
<width>170</width>
<height>66</height>
</rect>
</property>
<property name="palette">
<palette>
<active>
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
<color>
<red>127</red>
<green>168</green>
<blue>168</blue>
</color>
<color>
<red>191</red>
<green>252</green>
<blue>252</blue>
</color>
<color>
<red>159</red>
<green>210</green>
<blue>210</blue>
</color>
<color>
<red>64</red>
<green>84</green>
<blue>84</blue>
</color>
<color>
<red>85</red>
<green>112</green>
<blue>112</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
<color>
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
<color>
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
<color>
<red>218</red>
<green>231</green>
<blue>250</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>128</blue>
</color>
<color>
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</active>
<disabled>
<color>
<red>128</red>
<green>128</green>
<blue>128</blue>
</color>
<color>
<red>127</red>
<green>168</green>
<blue>168</blue>
</color>
<color>
<red>191</red>
<green>252</green>
<blue>252</blue>
</color>
<color>
<red>146</red>
<green>193</green>
<blue>193</blue>
</color>
<color>
<red>64</red>
<green>84</green>
<blue>84</blue>
</color>
<color>
<red>85</red>
<green>112</green>
<blue>112</blue>
</color>
<color>
<red>128</red>
<green>128</green>
<blue>128</blue>
</color>
<color>
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
<color>
<red>128</red>
<green>128</green>
<blue>128</blue>
</color>
<color>
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
<color>
<red>218</red>
<green>231</green>
<blue>250</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>128</blue>
</color>
<color>
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>255</blue>
</color>
<color>
<red>255</red>
<green>0</green>
<blue>255</blue>
</color>
</disabled>
<inactive>
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
<color>
<red>127</red>
<green>168</green>
<blue>168</blue>
</color>
<color>
<red>191</red>
<green>252</green>
<blue>252</blue>
</color>
<color>
<red>146</red>
<green>193</green>
<blue>193</blue>
</color>
<color>
<red>64</red>
<green>84</green>
<blue>84</blue>
</color>
<color>
<red>85</red>
<green>112</green>
<blue>112</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
<color>
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
<color>
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
<color>
<red>218</red>
<green>231</green>
<blue>250</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>128</blue>
</color>
<color>
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
<color>
<red>0</red>
<green>0</green>
<blue>255</blue>
</color>
<color>
<red>255</red>
<green>0</green>
<blue>255</blue>
</color>
</inactive>
</palette>
</property>
<property name="focusPolicy">
<enum>WheelFocus</enum>
</property>
<property name="lineWidth">
<number>5</number>
</property>
<property name="hScrollBarMode">
<enum>AlwaysOff</enum>
</property>
<property name="dragAutoScroll">
<bool>true</bool>
</property>
<property name="textFormat">
<enum>PlainText</enum>
</property>
<property name="text">
<string></string>
</property>
<property name="linkUnderline">
<bool>false</bool>
</property>
<property name="wordWrap">
<enum>WidgetWidth</enum>
</property>
<property name="wrapPolicy">
<enum>Anywhere</enum>
</property>
<property name="undoDepth">
<number>100</number>
</property>
<property name="autoFormatting">
<set>AutoAll</set>
</property>
</widget>
<widget class="QTextEdit">
<property name="name">
<cstring>textEdit2</cstring>
</property>
<property name="geometry">
<rect>
<x>100</x>
<y>10</y>
<width>160</width>
<height>60</height>
</rect>
</property>
<property name="textFormat">
<enum>PlainText</enum>
</property>
<property name="wrapPolicy">
<enum>Anywhere</enum>
</property>
<property name="autoFormatting">
<set>AutoNone</set>
</property>
</widget>
</widget>
<connections>
<connection>
<sender>Clear_but</sender>
<signal>clicked()</signal>
<receiver>textEdit1</receiver>
<slot>clear()</slot>
</connection>
<connection>
<sender>Cancel_but</sender>
<signal>clicked()</signal>
<receiver>Form1</receiver>
<slot>close()</slot>
</connection>
</connections>
<slots>
<slot>clear()</slot>
<slot>SendSlot()</slot>
</slots>
<layoutdefaults spacing="6" margin="11"/>
</UI>
[/size]
Есть главный поток, который рисует форму. И второй otherthread который должен нарисовать в поле tEdit2 некоторый текст. Однако происходит ошибка: 2 потка пытаются использовать одни данные.
//QPixmap::operator=: Cannot assign to pixmap during painting
Как её исправить?