[Qt-interest] change centralwidget in qtcreator
Yuvraaj Kelkar
yuvraaj at gmail.com
Wed Apr 27 19:11:43 CEST 2011
Use QMainWindow::setCentralWidget
http://doc.qt.nokia.com/4.7/qmainwindow.html#setCentralWidget
Delete the original central widget and later when using the new
central widget that you saved, make sure you typecast it properly.
2011/4/27 zhao_yunsong <zhao_yunsong at 163.com>:
> I want to change the centralwidget (which is a instance of QWidget by
> default) of a mainwindow program in qtcreator, how can i do this.
>
>
>
>
> 2011-04-28
> ________________________________
> zhao_yunsong
> ________________________________
> 发件人: qt-interest-request
> 发送时间: 2011-04-28 00:54:56
> 收件人: qt-interest
> 抄送:
> 主题: Qt-interest Digest, Vol 5, Issue 127
> Send Qt-interest mailing list submissions to
> qt-interest at qt.nokia.com
> To subscribe or unsubscribe via the World Wide Web, visit
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
> or, via email, send a message with subject or body 'help' to
> qt-interest-request at qt.nokia.com
> You can reach the person managing the list at
> qt-interest-owner at qt.nokia.com
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Qt-interest digest..."
> Today's Topics:
> 1. Re: large xml over the network - problem (Jeroen De Wachter)
> 2. Re: large xml over the network - problem (Bill Crocker)
> 3. Re: large xml over the network - problem (Jeroen De Wachter)
> 4. Re: Adding arbitrary depth to Graphics Scene & Friends (Jason H)
> ----------------------------------------------------------------------
> Message: 1
> Date: Wed, 27 Apr 2011 17:20:39 +0200
> From: Jeroen De Wachter <jeroen.dewachter at elis.ugent.be>
> Subject: Re: [Qt-interest] large xml over the network - problem
> To: franki <franki at franki.eu.org>
> Cc: qt-interest at trolltech.com
> Message-ID: <1303917639.23813.22.camel at LoneWolf>
> Content-Type: text/plain; charset="UTF-8"
> Hey Marek,
> Whenever the size of a data type is important, I try to use types that
> specify the size in no uncertain terms (this avoids surprises on other
> platforms/with other compilers), so I'd use quint32 or uint32_t
> Your solution with sending the size first should work.
> However, Qt also provides some serialization/deserialization
> functionality all on its own (which takes care of communicating the
> length before sending the type)
> You should take a look at QDataStream:
> http://doc.trolltech.com/4.7/qdatastream.html
> Kind regards,
> Jeroen
> On Wed, 2011-04-27 at 16:50 +0200, franki wrote:
>> Wednesday 27 of April 2011 16:23:22 Jeroen.DeWachter at elis.ugent.be napisa?(a):
>> > Hi,
>> >
>> > You do know quint16 is limited to 65536, right?
>> > So if you're using strings that are longer than that (and you seem to do
>> > just that, judging from your example), the length can't be specified
>> > correctly in the two bytes you are trying to use for it...
>>
>> Yes... in my example block.size() on server side is 69496 and quint16 is
>> limited to 65536 so... 65536 - 69496 =- 3960 and in my example quint size was
>> 3958 (very close), so If I change from quint16 to int (which is four bytes,
>> or at least I think so?) should it be OK ?
>>
>> And answering to Jason, I putted the size of packet at the beginning because
>> sometimes there are lots of packets emitted from server to client, each with
>> some unique data, how do I know if last message xml has ended before I start
>> parsing it? I'm only beginner but wouldn't be a problem when a few xml's are
>> sended one after another and client hasn't finished processing of first xml
>> command when two or more has arrived. You know, what can separate xml's on
>> client side? to process then one by one? I thought that I can ensure myself
>> that I'm reading these xml's one by one by putting size at the beginning?
>> (besides it was in fortune client example)
>>
>> best regards
>> Marek
>>
>> >
>> > That would certainly be an explanation for the huge discrepancy in your
>> > block size and the quint size...
>> >
>> > Kind regards,
>> >
>> > Jeroen
>> >
>> > Quoting franki <franki at franki.eu.org>:
>> > > Hi all,
>> > >
>> > > I have client-server application which exchange data using xml's
>> > > over the net.
>> > > With relatively small xml's everything goes fine, but when I try to send
>> > > big ones there is problem with receiving it (not always just from time to
>> > > time), and if I double the size of xml, they are always lost.
>> > > Snippet of code on server side:
>> > >
>> > > void NetThread::sendToClient(QDomDocument xml) {
>> > > QByteArray block;
>> > > QDataStream out(&block, QIODevice::ReadWrite);
>> > > out.setVersion(QDataStream::Qt_4_0);
>> > > out << (quint16)0;
>> > > out << xml.toString();
>> > > out.device()->seek(0);
>> > > out << (quint16)(block.size() - sizeof(quint16));
>> > > qDebug() <<" quint size:"<<(quint16)(block.size() - sizeof(quint16))
>> > > qDebug() <<" block size:"<<block.size();
>> > > qDebug() <<" string size:"<<xml.toString().size();
>> > > tcpSocket->write(block);
>> > > }
>> > >
>> > > code on client side look's like this (dataSize is quint16):
>> > > void NetManager::readData() {
>> > > QDataStream in(socket);
>> > > in.setVersion(QDataStream::Qt_4_0);
>> > > if (dataSize == 0) {
>> > > if (socket->bytesAvailable() < (int)sizeof(quint16))
>> > > return;
>> > > in >> dataSize;
>> > > }
>> > > if(socket->bytesAvailable() < dataSize)
>> > > return;
>> > >
>> > > QString text;
>> > > in >> text;
>> > > qDebug() << " dataSize:"<<dataSize<<" received:"<<text;
>> > > dataSize=0;
>> > > this->parseData(text);
>> > > if(socket->bytesAvailable())
>> > > this->readData();
>> > > }
>> > >
>> > > On the server side, during transmission debug says:
>> > > quint size: 3958
>> > > block size: 69496
>> > > string size: 34745
>> > >
>> > > On client side when there is successful transmision I got:
>> > > NetManager::readData dataSize: 3958 received: "very long_xml_string"
>> > >
>> > > When there is problem with transmission I got:
>> > > Debug: NetManager::readData bytes: 3958 received: ""
>> > > Debug: NetManager::parseData parse error
>> > > Debug: NetManager::readData bytes: 61 received: ""
>> > > Debug: NetManager::parseData parse error
>> > > Debug: NetManager::readData bytes: 51 received: ""
>> > > Debug: NetManager::parseData parse error
>> > > Debug: NetManager::readData bytes: 56 received: ""
>> > > Debug: NetManager::parseData parse error
>> > >
>> > > So in second example the packet length is the same 3958 but the function
>> > > is called 4 times and I'm quite sure that application on server side
>> > > doesn't send anything except for this xml.
>> > > So please can someone point me on my errors?
>> > >
>> > > best regards
>> > > Marek
>> > > _______________________________________________
>> > > Qt-interest mailing list
>> > > Qt-interest at qt.nokia.com
>> > > http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>> >
>> > ----------------------------------------------------------------
>> > This message was sent using IMP, the Internet Messaging Program.
>>
>>
> ------------------------------
> Message: 2
> Date: Wed, 27 Apr 2011 11:24:23 -0400
> From: Bill Crocker <william.crocker at analog.com>
> Subject: Re: [Qt-interest] large xml over the network - problem
> To: "qt-interest at trolltech.com" <qt-interest at trolltech.com>
> Message-ID: <4DB83527.1030204 at analog.com>
> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed
> Jason H wrote:
>> Why in the world are you doing that?
>>
>> in >> buffer;
> Because this will block until all of the data arrives
> and his app may have better things to do?
> Bill
>> QDomDocument xml;
>> xml.setContent(buffer.toString());
>>
>>
>>
>>
>>
>> ----- Original Message ----
>> From: franki <franki at franki.eu.org>
>> To: qt-interest at trolltech.com
>> Sent: Wed, April 27, 2011 10:08:35 AM
>> Subject: [Qt-interest] large xml over the network - problem
>>
>> Hi all,
>>
>> I have client-server application which exchange data using xml's over the net.
>> With relatively small xml's everything goes fine, but when I try to send big
>> ones there is problem with receiving it (not always just from time to time),
>> and if I double the size of xml, they are always lost.
>> Snippet of code on server side:
>>
>> void NetThread::sendToClient(QDomDocument xml) {
>> QByteArray block;
>> QDataStream out(&block, QIODevice::ReadWrite);
>> out.setVersion(QDataStream::Qt_4_0);
>> out << (quint16)0;
>> out << xml.toString();
>> out.device()->seek(0);
>> out << (quint16)(block.size() - sizeof(quint16));
>> qDebug() <<" quint size:"<<(quint16)(block.size() - sizeof(quint16))
>> qDebug() <<" block size:"<<block.size();
>> qDebug() <<" string size:"<<xml.toString().size();
>> tcpSocket->write(block);
>> }
>>
>> code on client side look's like this (dataSize is quint16):
>> void NetManager::readData() {
>> QDataStream in(socket);
>> in.setVersion(QDataStream::Qt_4_0);
>> if (dataSize == 0) {
>> if (socket->bytesAvailable() < (int)sizeof(quint16))
>> return;/net/neuro/disk1/apache/website/htdocs/adice/adiceinfo/log_r10.txt
>> in >> dataSize;
>> }
>> if(socket->bytesAvailable() < dataSize)
>> return;
>>
>> QString text;
>> in >> text;
>> qDebug() << " dataSize:"<<dataSize<<" received:"<<text;
>> dataSize=0;
>> this->parseData(text);
>> if(socket->bytesAvailable())
>> this->readData();
>> }
>>
>> On the server side, during transmission debug says:
>> quint size: 3958
>> block size: 69496
>> string size: 34745
>>
>> On client side when there is successful transmision I got:
>> NetManager::readData dataSize: 3958 received: "very long_xml_string"
>>
>> When there is problem with transmission I got:
>> Debug: NetManager::readData bytes: 3958 received: ""
>> Debug: NetManager::parseData parse error
>> Debug: NetManager::readData bytes: 61 received: ""
>> Debug: NetManager::parseData parse error
>> Debug: NetManager::readData bytes: 51 received: ""
>> Debug: NetManager::parseData parse error
>> Debug: NetManager::readData bytes: 56 received: ""
>> Debug: NetManager::parseData parse error
>>
>> So in second example the packet length is the same 3958 but the function is
>> called 4 times and I'm quite sure that application on server side doesn't
>> send anything except for this xml.
>> So please can someone point me on my errors?
>>
>> best regards
>> Marek
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at qt.nokia.com
>> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at qt.nokia.com
>> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>>
> ------------------------------
> Message: 3
> Date: Wed, 27 Apr 2011 17:43:35 +0200
> From: Jeroen De Wachter <jeroen.dewachter at elis.ugent.be>
> Subject: Re: [Qt-interest] large xml over the network - problem
> To: franki <franki at franki.eu.org>
> Cc: qt-interest at trolltech.com
> Message-ID: <1303919015.23813.30.camel at LoneWolf>
> Content-Type: text/plain; charset="UTF-8"
> Hey Marek,
> I just remembered I once talked about the QDataStream on the qt IRC
> channel and it might be important for you.
> If you send a large chunk of data through the QDataStream, if might
> cause trouble with buffering (in combination with the tcp connection) or
> if the connection shuts down (and you may have no way of knowing sending
> the data failed). I don't remember the specifics, I just recall there
> was some discussion.
> Maybe you could test the QDataStream stuff and just see if it works (I
> think it's more elegant than breaking up a string into size and data
> fields yourself), but keep your current solution in mind as a fallback.
> Just wanted to give you a heads-up...
> Kind regards,
> Jeroen
> On Wed, 2011-04-27 at 17:20 +0200, Jeroen De Wachter wrote:
>> Hey Marek,
>>
>> Whenever the size of a data type is important, I try to use types that
>> specify the size in no uncertain terms (this avoids surprises on other
>> platforms/with other compilers), so I'd use quint32 or uint32_t
>>
>> Your solution with sending the size first should work.
>>
>> However, Qt also provides some serialization/deserialization
>> functionality all on its own (which takes care of communicating the
>> length before sending the type)
>> You should take a look at QDataStream:
>>
>> http://doc.trolltech.com/4.7/qdatastream.html
>>
>> Kind regards,
>>
>> Jeroen
>>
>> On Wed, 2011-04-27 at 16:50 +0200, franki wrote:
>> > Wednesday 27 of April 2011 16:23:22 Jeroen.DeWachter at elis.ugent.be napisa?(a):
>> > > Hi,
>> > >
>> > > You do know quint16 is limited to 65536, right?
>> > > So if you're using strings that are longer than that (and you seem to do
>> > > just that, judging from your example), the length can't be specified
>> > > correctly in the two bytes you are trying to use for it...
>> >
>> > Yes... in my example block.size() on server side is 69496 and quint16 is
>> > limited to 65536 so... 65536 - 69496 =- 3960 and in my example quint size was
>> > 3958 (very close), so If I change from quint16 to int (which is four bytes,
>> > or at least I think so?) should it be OK ?
>> >
>> > And answering to Jason, I putted the size of packet at the beginning because
>> > sometimes there are lots of packets emitted from server to client, each with
>> > some unique data, how do I know if last message xml has ended before I start
>> > parsing it? I'm only beginner but wouldn't be a problem when a few xml's are
>> > sended one after another and client hasn't finished processing of first xml
>> > command when two or more has arrived. You know, what can separate xml's on
>> > client side? to process then one by one? I thought that I can ensure myself
>> > that I'm reading these xml's one by one by putting size at the beginning?
>> > (besides it was in fortune client example)
>> >
>> > best regards
>> > Marek
>> >
>> > >
>> > > That would certainly be an explanation for the huge discrepancy in your
>> > > block size and the quint size...
>> > >
>> > > Kind regards,
>> > >
>> > > Jeroen
>> > >
>> > > Quoting franki <franki at franki.eu.org>:
>> > > > Hi all,
>> > > >
>> > > > I have client-server application which exchange data using xml's
>> > > > over the net.
>> > > > With relatively small xml's everything goes fine, but when I try to send
>> > > > big ones there is problem with receiving it (not always just from time to
>> > > > time), and if I double the size of xml, they are always lost.
>> > > > Snippet of code on server side:
>> > > >
>> > > > void NetThread::sendToClient(QDomDocument xml) {
>> > > > QByteArray block;
>> > > > QDataStream out(&block, QIODevice::ReadWrite);
>> > > > out.setVersion(QDataStream::Qt_4_0);
>> > > > out << (quint16)0;
>> > > > out << xml.toString();
>> > > > out.device()->seek(0);
>> > > > out << (quint16)(block.size() - sizeof(quint16));
>> > > > qDebug() <<" quint size:"<<(quint16)(block.size() - sizeof(quint16))
>> > > > qDebug() <<" block size:"<<block.size();
>> > > > qDebug() <<" string size:"<<xml.toString().size();
>> > > > tcpSocket->write(block);
>> > > > }
>> > > >
>> > > > code on client side look's like this (dataSize is quint16):
>> > > > void NetManager::readData() {
>> > > > QDataStream in(socket);
>> > > > in.setVersion(QDataStream::Qt_4_0);
>> > > > if (dataSize == 0) {
>> > > > if (socket->bytesAvailable() < (int)sizeof(quint16))
>> > > > return;
>> > > > in >> dataSize;
>> > > > }
>> > > > if(socket->bytesAvailable() < dataSize)
>> > > > return;
>> > > >
>> > > > QString text;
>> > > > in >> text;
>> > > > qDebug() << " dataSize:"<<dataSize<<" received:"<<text;
>> > > > dataSize=0;
>> > > > this->parseData(text);
>> > > > if(socket->bytesAvailable())
>> > > > this->readData();
>> > > > }
>> > > >
>> > > > On the server side, during transmission debug says:
>> > > > quint size: 3958
>> > > > block size: 69496
>> > > > string size: 34745
>> > > >
>> > > > On client side when there is successful transmision I got:
>> > > > NetManager::readData dataSize: 3958 received: "very long_xml_string"
>> > > >
>> > > > When there is problem with transmission I got:
>> > > > Debug: NetManager::readData bytes: 3958 received: ""
>> > > > Debug: NetManager::parseData parse error
>> > > > Debug: NetManager::readData bytes: 61 received: ""
>> > > > Debug: NetManager::parseData parse error
>> > > > Debug: NetManager::readData bytes: 51 received: ""
>> > > > Debug: NetManager::parseData parse error
>> > > > Debug: NetManager::readData bytes: 56 received: ""
>> > > > Debug: NetManager::parseData parse error
>> > > >
>> > > > So in second example the packet length is the same 3958 but the function
>> > > > is called 4 times and I'm quite sure that application on server side
>> > > > doesn't send anything except for this xml.
>> > > > So please can someone point me on my errors?
>> > > >
>> > > > best regards
>> > > > Marek
>> > > > _______________________________________________
>> > > > Qt-interest mailing list
>> > > > Qt-interest at qt.nokia.com
>> > > > http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>> > >
>> > > ----------------------------------------------------------------
>> > > This message was sent using IMP, the Internet Messaging Program.
>> >
>> >
>>
>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at qt.nokia.com
>> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
> ------------------------------
> Message: 4
> Date: Wed, 27 Apr 2011 09:47:20 -0700 (PDT)
> From: Jason H <scorp1us at yahoo.com>
> Subject: Re: [Qt-interest] Adding arbitrary depth to Graphics Scene &
> Friends
> To: Javier Urien <javierurien at gmail.com>
> Cc: qt-interest at trolltech.com
> Message-ID: <698755.91203.qm at web120716.mail.ne1.yahoo.com>
> Content-Type: text/plain; charset="us-ascii"
> In theory no, but in practice yes.
> You'll have to make a QAppliction instance, but you [probably] won't have to
> call app.exec().
> main ()
> {
> QApplication app;
> QGraphicsView gv...
> /* do your manipulation here */
> /* do your output here */
> /* no need for exec (most likely) */
> return 0;
> }
> ________________________________
> From: Javier Urien <javierurien at gmail.com>
> To: Jason H <scorp1us at yahoo.com>
> Cc: qt-interest at trolltech.com
> Sent: Wed, April 27, 2011 10:43:29 AM
> Subject: Re: [Qt-interest] Adding arbitrary depth to Graphics Scene & Friends
> On Tue, Apr 26, 2011 at 18:28, Javier Urien <javierurien at gmail.com> wrote:
>>
>>
>>On Tue, Apr 26, 2011 at 16:20, Jason H <scorp1us at yahoo.com> wrote:
>>
>>Yes. a Qt Image IO plugin.
>>>
>>>http://doc.qt.nokia.com/qq/qq17-imageio.html
>>>
>>>
>>Excellent!!!
>>
>>
>>Thanks for all your answers!
> One more question. Does all this depend on the application loop or can it be
> used without a QApplication instance?
> Regards.
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: http://lists.qt.nokia.com/pipermail/qt-interest/attachments/20110427/3da636ad/attachment.html
> ------------------------------
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
> End of Qt-interest Digest, Vol 5, Issue 127
> *******************************************
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
>
More information about the Qt-interest-old
mailing list