工作笔记 第三季

来源:互联网 发布:ip批量查询软件 编辑:程序博客网 时间:2024/04/27 21:12

Cand C++ Note Records

 

Part for QT:

 

 

Part for C++:

1、指向指针的指针和多维数组的指针的关系

 

物理引擎方面的问题:

 

 

Part for MFC:

1、在MFC的编译中有的时候会报unexpectedend of file while looking for precompiled head。

我实在编写Box2D的时候,增加.h和.cpp文件的时候发生的!

解决方案:在工程的属性里面选择NO useprecompile head的选项。

 

 

 

ETA软件的设计:

A、          需求技术:

Box2D技术、OpenGL技术、GDI+技术、Circuit2D技术、C++、MFC、Object C、Qt,Java、Net

B、          功能设想:

a、           能够仿真信号频率的过程。

b、          能够实现仿真电路。

c、           能够实现三维的电磁学的多维分析。

d、          扩展到Mac平台、手机平台(精简版)、网页版、Linux版、英文版

Mac虚拟机的技术积累:

a、           虚拟机与主机的通信。

b、           

编译安装方面:

1、配置igloo与VS连接的问题

ProDoc\03_开发文档\03_Coding\ProDoc_VS   E:\ProDoc

2、配置服务器端的wincvs的问题

 

3、管理项目流程图

 

 

 

 

 

 

 

 

 

 

 

 

 


4、如何创建Qt的应用程序图标(Setting theApplication Icon)

First, create an ICO format bitmapfile that contains the icon image. This can be done with e.g. Microsoft VisualC++: SelectFile|New, then selecttheFiletab in the dialog thatappears, and chooseIcon. (Note thatyou do not need to load your application into Visual C++; here we are onlyusing the icon editor.)

Store the ICO file in yourapplication's source code directory, for example, with the name myappico.ico.Then, create a text file called, say, myapp.rc in which you put a single lineof text:

 IDI_ICON1    ICON    DISCARDABLE     "myappico.ico"

Finally, assuming you are usingqmake to generate your makefiles, add this line to your myapp.pro file:

 RC_FILE = myapp.rc

Regenerate your makefile and yourapplication. The .exe file will now be represented with your icon in Explorer.

5、Eclipse中打开Qt的函数方法

用Ctrl+Tab,之前要用鼠标选中这个函数。

6、CVS更新的时候设置为

7、Eclipse与Wincvs联合编写工程

CVS增加模块

 

 

 

思想方面的问题:

 

发展方向:

1、熟练掌握移植手机软件的方法。

2、了解黑莓、诺基亚、微软、魅族、苹果、安卓、Linux手机操作系统的结构和软件的移植与发布。

3、熟练掌握JS的编程方法,用JS搭出一个框架出来。

4、解析Prodoc的构架。

5、熟练掌握Java,做一个Java中心思想的框架出来。

6、想做一个专门用于仿真的软件包括力学、磁场学、电学的仿真能够在各种手机上面跑的版本、操作系统上跑、网页上面跑的。

7、了解一下GWT相关的知识和内容。

8、学习一下FLEX,争取做一个网页的框架出来。

9、了解一下视频解码器的原理。

10、了解一下OpenGL的相关程序。

具体任务:

1、完成将Qt的画弧机制变换成为GDI+的画图补充方法。(完成)

2、添加弹簧秤、游标卡尺、电流表、电压表、电灯的属性框完成动态功能的展示。(完成)

3、搭建魅族手机的开发环境。(完成)

4、学习Box2D的机制,编写电路相似引擎的库文件。

            4.1、今天需要写死一些方法来检查程序。(完成)

            4.2、今天开始调试算法的具体内容(完成)

5、弹簧秤应该加上一个指针指向需要指向的刻度、同时改正一下拉弹簧秤时,弹簧的错误的情况。(完成)

6、正陵柱的侧面填充无法填充。(完成)

7、化学里面直导管的属性框连接有问题。(王勇已完成)

8、在标注的地方发现标注的不对。(完成)

9、图形正列化修改。(改为王勇做)

10、电路引擎完全搭建。(完成)

11、画弧的问题_原来我改的问题()

12、等腰梯形问题(完成)

13、游标卡尺的对齐问题(完成)

14、圆冠的问题()

15、点填充

16、滑动变阻器的调整()

 

 

1、为什么xml无法读取出来

解答:

首先确认XML是否符合标准,用UE来打开。Xml的读取顺序(对于QXmlStreamReader)是依次读取标签。

例子:请查询邮箱中QXmlStreamReader的例子

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


1                     XML Basic Concepts:
Element | Name Convention | Attributes | Empty Element | Nesting and depth | Root |PI | Comments | CDATA | DTD | Entities

2                     Introduction to STL XmlStreamReaderDOM | SAX | Stream parser ...

3                     Capability of STL XmlStreamReader

4                     STL XmlStreamReader Diff

5                     Great Tolerance upon HTML and beyond

6                     Application: Extract HTML text

7                     Application: HTML validator

8                     Application: XML validator

9                     class StreamCacher : public StreamReader

10                 Back-and-forth Bi-direction parsing

11                 Other XML parsers

12                 Related junk

XML Basic Concepts

Element

The building block of XML is element.

Each element has a name and a content.

<p>Hello XML</p>

 

There are tags. Call them "start tag" and "end tag" or "opening tag" and "closing tag".

When this element is read by a parser, tokens are:

start element

characters

end element

 

Element's Name Convention

§                Element names must start with either a letter or a underscore; the rest contains of letters, digits, the underscore, the dot, or a hyphen.

§                Spaces are not allowed in names.

§                The colon ':' is reserved for namespaces.

§                XML tags are case-sensitive, while HTML tags are not.

Attributes

Element can have 0, 1 or more attributes. Attributes have name-value pairs, where attribute names follow the same rules as elements names.

Attribute value must be enclosed in double or single quotation marks, for example,

1                                             The following two elements are equivalent.

  <param color="r='0' g='128' b='255'" />

  <param color='r="0" g="128" b="255"' />

 

Empty Element (self-closed element, or no content element)

<img src="image01.jpg"/>

 

2                                             or,

<img src="image01.jpg"></img>

 

3                                             Tokens are "start element" followed by "end element", no "characters" in between.

The following three examples are equivalent in XML:

<p/>

<p   />

<p></p>

 

Nesting and depth

4                                             Nesting means element contains other element. Depth means the steps to root.

Root

5                                             An XML document must have and only have one root.

Processing instructions (PI)

6                                             First line of an XML may have:

<?xmlversion="1.0" encoding="UTF-8" standalone="yes"?>

 

7                                             A pi has an opening and closing tags, a target (name), and a data (content).

Comments

<!-- some comments -->

 

CDATA (character data - not markup)

<![CDATA[ ... ]]>

 

DTD (Document Type Definition)

<!DOCTYPE ... ]>

 

Entities escape

Original

Escaped

less than (<)

&lt;

greater than (>)

&gt;

ampersand (&)

&amp;

apostrophe (')

&apos;

quote (")

&quot;

List of XML and HTML character entity references

XML Stream Parser

Most XML parsers are DOM, SAX or SAX2 types.

DOM parser loads the whole tree in memory, it does not work for big file;

SAX parser which has O(0) complexity, scalable, but I don't like its passive data pushing and poor structure.

Let's work on a new parser for seeking simplicity, flexibility, and efficiency, and better structure. That is a stream parser with data pulling mechanism base on token and zero cost for big XML parsing.

1) Three popular tokens:

o                  START_ELEMENT

o                  END_ELEMENT, and

o                  CHARACTERS

2) One pulling method in your own driving loop

    readNext();

 

3) One descent parsing pattern:

    while (!reader->atEnd()) {

        reader->readNext(); // pull data out

       

        if (reader->isEndElement()) {

            ...     // exit conditions

            break;

        }

        else if (reader->isStartElement()) {

            ...     // objects descent handling

        }

        else if (reader->isCharacters() {

            std::string t = reader->text();

            ...     // element content, or characters in between

        }

    }

 

From these three points you can image how simple the stream parse is!

Big advantage of the stream parser is to build a recursive descent object-orientated parsing process. For example, in Office Open XML, a paragraph (p) contains a property list (pPr) and several runs; each run (r) contains one run property list (rPr), text (t), or inline level of objects.

<p>    <pPr>

        ...

    </pPr>

    <r>        <rPr>

            ...

        </rPr>

        <t> ... </t>

    </r>

    <r>

        <pict>

            ...

            <txtbox>                <p>

                    ...

                </p>

            </txtbox>

        </pict>

    </r>

</p>

 

To handle paragraph we have:

void Xxx::readParagraph()

{

    while (!reader->atEnd()) {

        reader->readNext();

        if (reader->isEndElement()) {

            if (reader->name() == "p") break;

        }

        else if (reader->isStartElement()) {

            if (reader->name() == "pPr") {

                readParagraphProperty();

            }

            else if (reader->name() == "r" ) {

                readRun();

            }

        }   

    }

}

 

void Xxx::readRun()

{

    while (!reader->atEnd()) {

        reader->readNext();

        if (reader->isEndElement()) {

            if (reader->name() == "r") break;

        }

        else if (reader->isStartElement()) {

            if (reader->name() == "rPr") {

                readRunProperty();

            }

            else if (reader->name() == "t" ) {

                readText();

            }

            else if (reader->name() == "pict") {

                readPicture();

            }

        }   

    }

}

 

Capability of XmlStreamReader

8                                             Report tag name and attributes at isStartElement()

    if (rdr->isStartElement()) {

      fstring name = rdr->name();

      fstring prefix = rdr->prefix();

      PairList a = rdr->attrs();

    }

 

9                                             Report tag name at isEndElement()

    if (rdr->isEndElement()) {

      fstring name = rdr->name();

      fstring prefix = rdr->prefix();

    }

 

10                                         Report text at isCharacters(). Also, answers if the text isWhitespace().

    if (rdr->isCharacters()) {

      if (!rdr->isWhitespace()) {

        fwstring text = rdr->text();

      }

    }

 

11                                         Report pi target and data.

    if (rdr->isProcessingInstruction()) {

      fstring target = rdr->name();

      fwstring data = rdr->text();

    }

 

12                                         Report comment, DTD, and CDATA by text()

    if (rdr->isComment()

      || rdr->isDTD()

      || rdr->isCDATA() ) {

        fwstring text = rdr->text();

    }  

 

13                                         Report Error:

    if (rdr->hasError()) {

      fstring errs = rdr->errstring();

    }

 

14                                         Report open tag count and depth of nesting (distance to root)

    int depth = rdr->depth();

    int tagCount = rdr->tagCount();

 

Line and column numbers

  while (!rdr->atEnd()) {

    rdr->readNext();

    size_t lineNumber = rdr->lineNumber();

    size_t columnNumber = rdr->columnNumber();

  }

 

For example,

<?xml version='1.0' encoding='utf-8' standalone='yes'?>

<body><p>

<!-- some comment  -->

This is <i>something</i>.

</p>

</body>

 


(line, column) numbers of each token ends at (line number starts from 1, column number starts from 0)

Character offset

15                                         Instead of line/column numbers, character offset is known at every token as well:

16                                         Spaces handling

§                Reported space(s):Any spaces sitting after a close angle '>' till a open angle '<' including line feed (line break or end-of-line / EOL character) get reported by text()



§                     Reduced/Abandoned space(s) between open angle '<' and close angle '>' :



All spaces sit after a tag name before the first attribute name are reduced to 1 space.

§                     All spaces sit between attributes are reduced to 1 space.

§                     Any spaces sitting around '=', before or after, are abandoned.

Public Member Functions

17                                         (link)

18                                         UTF-8 Encoding: XmlStreamReader has a Source to read.

19                                         FileSource is a Source.

20                                         At the time to open a file, one can specify the encoding:

fopen_s(&fp, fileName.c_str(), "r, ccs=UTF-8");

 

Read wide char:

bool FileSource::read(uint16 &ch)

{

  if (!fp) return false;

  int tmp = ::getwc(fp); // must be a signed type.

  if (tmp == WEOF) {     // EOF == -1

    ch = 0;  

    return false;

  }

  ch = tmp;

  return true;

}

 

Debug view:

Tree view:

Notepad++ displays well in "Encoded in UTF-8 without BOM"

STL XmlStreamReader diff

Namespace declaration report

21                                         Our STL XmlStreamReader reports namespace declaration(s) in different way. For example,

 <document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" />

 

XmlStreamReader treats the namespace declaration nothing more than an attribute name-value pair, where

§                the prefix is "xmlns",

§                the local name is "w",

§                the qualified name is "xmlns:w",

§                the value is "http://...".

    if (rdr->isStartElement()) {

      if (rdr->hasAttrs()) {

        StringPair pair = rdr->attrs().at(0);

        fwstring prefix = pair.prefix(); // "xmlns"

        fwstring name = pair.localName();// "w"

        fwstring value = pair.second;    // "http:..."

      }

    }

 

With QXmlStremReader

    if (rdr.isStartElement()) {

      QString tagName = rdr.name().toString();

      QXmlStreamAttributes a = rdr.attributes();

      int n = a.size();

      QXmlStreamNamespaceDeclarations namespaces = rdr.namespaceDeclarations();

      if (!namespaces.isEmpty()) {

        // The QXmlStreamNamespaceDeclaration class is defined to be

        //  a QVector of QXmlStreamNamespaceDeclaration.     

        QXmlStreamNamespaceDeclaration ns = namespaces[0];

        QString uri = ns.namespaceUri().toString(); // "http:..."

        QString prefix = ns.prefix().toString();    // "w"

      }

    }

 

The qdoc says: "If the state() is StartElement, this function returns the element's namespace declarations. Otherwise an empty vector is returned." Problem is how to know there comes a namespace declaration. We cannot try to get, for every start elements, a possible list of declarations, and then, check the vector is empty or not.

Valid/Invalid with/without namespace declaration

22                                         For example,

<!-- The following prefix is not declared -->

<w:p/>

 

§                It is invalid in QXmlStreamReader: "Namespace prefix 'w' not declared"

§                It is invalid in Xerces: "The prefix 'w' has not been mapped to any URI at row:2 col:7"

§                It is valid in QDOM, it is, also, valid in our STL XmlStreamReader. We're not stop parsing. Let it go!

What happen if an element has a repeated attribute?

23                                         For example,

<param   a="1"  a="2"/>

 

§                STL XmlStreamReader has no validation on repeated attribute(s). It uses a list for attributes.

§                QDOM uses map, so it moves to the latest value.

§                QXmlStreamReader Error: "Attribute redefined."

§                Xerces stops parsing on such an error.

Attribute value restore/escape?

24                                         No, STL XmlSreamReader does not restore/escape anything. It's a RAW reader. For examples, this is a valid XML where an attribute value is expressed in different ways.

<params>

  <param color="r='0' g='128' b='255'" />

  <param color='r="0" g="128" b="255"' />

  <param color="r=&quot;0&quot; g=&quot;128&quot; b=&quot;255&quot;" />

  <param color='r=&apos;0&apos; g=&apos;128&apos; b=&apos;255&apos;' />

</params>

 

STL XmlSreamReader reports these elements as what you see, but normal readers, such as, QXmlSreamReader, Xerces SAX2, report them in restored format.  

    if (rdr.isStartElement()) {

      QString tagName = rdr.name().toString();

      QXmlStreamAttributes attributes = rdr.attributes();

      foreach(QXmlStreamAttribute a, attributes) {

        QString prefix = a.prefix().toString();

        QString name = a.name().toString();

        QString value = a.value().toString();  

      }

    }

 

Characters Report difference

25                                         For example, in text editor an element like this:

<p>Italic font example: &lt;i&gt;italic&gt;&lt;/i&gt;</p>

 

STL XmlStreamReader reports the whole element content in one report, but QXmlStreamReader (version 4.4.1) reports 6 times. They are:

1: "Italic font example: "

2: "<i"

3: ">italic"

4: ">"

5: "</i"

6: ">"

 

It is broken down everytime when an escaped character is encountered, and represented as restored form, for example, "&lt;" by "<".

Another example,

Tokens:

Four characters are:

"He said: "

""I"

"'ll come again."

"""

 

Great Tolerance upon HTML and beyond

13                 Many HTML files are not well-formed XML, because of this reason, many XML parsers fail. My STL XmlStreamReader has no such a problem. It can extract content or do searching smoothly among html files...

No problem if close tags are missing.

1                                             Very often in HTML some tags have open tags but no close tags, for examples, <P>, LI, <BR>, <IMG>, <HR> in following HTML:

<BODY>

<P>The first paragraph has a list:

  <UL>

    <LI>First item

    <LI>Second item

    <LI>Last item    

  </UL>

<P>The second paragraph has <IMG SRC="google.png">image,

line break <BR> and horizontal line <HR>

</BODY>

 

Its token list is:

       Token    Line    Column  Offset  Text

START_DOCUMENT  1   1   1  

START_ELEMENT   1   6   6   BODY

CHARACTERS  2   1   8  

START_ELEMENT   2   3   10  P

CHARACTERS  3   3   45  The first paragraph

START_ELEMENT   3   6   48  UL

CHARACTERS  4   5   54 

START_ELEMENT   4   8   57  LI

CHARACTERS  5   5   73  First item

START_ELEMENT   5   8   76  LI

CHARACTERS  6   5   93  Second item

START_ELEMENT   6   8   96  LI

CHARACTERS  7   3   111 Last item

END_ELEMENT 7   7   115 UL

CHARACTERS  8   1   117

START_ELEMENT   8   3   119 P

CHARACTERS  8   29  145 The second paragraph

START_ELEMENT   8   50  166 IMG

CHARACTERS  9   12  186 image, line break

START_ELEMENT   9   15  189 BR

CHARACTERS  9   37  211  and horizental line

START_ELEMENT   9   40  214 HR

CHARACTERS  10  1   216

END_ELEMENT 10  7   222 BODY

END_DOCUMENT    10  7   222

 

2                                             Nesting problem is OK, for example, bold and italic are crossed.

<p>Some <b>bold <i>italic</b> text</i></p>

 

Its token list is:

       Token    Line    Column  Offset  Text

START_DOCUMENT  1   1   1  

START_ELEMENT   1   3   3   p

CHARACTERS  1   9   9   Some

START_ELEMENT   1   11  11  b

CHARACTERS  1   17  17  bold

START_ELEMENT   1   19  19  i

CHARACTERS  1   26  26  italic

END_ELEMENT 1   29  29  b

CHARACTERS  1   35  35   text

END_ELEMENT 1   38  38  i

END_ELEMENT 1   42  42  p

END_DOCUMENT    1   42  42 

 

3                                             No problem if attribute values are not quoted, for example,

<p>Here is an image <img width=100 height=200> with unquoted attributes.

 

Its token list is:

       Token    Line    Column  Offset  Text

START_DOCUMENT  1   1   1  

START_ELEMENT   1   3   3   p

CHARACTERS  1   21  21  Here is an image

START_ELEMENT   1   46  46  img

CHARACTERS  1   73  73   with unquoted attri...

END_ELEMENT 1   76  76  p

END_DOCUMENT    1   76  76      

 

4                                             No problem if attribute section has litter, for example,

<div class="bodysmall" float: left;" sdkjjf dfjsdhkfhsd>

 



Click above image for a token inspector demo, where as it browsers through every token in a list widget (right-hand), token string, token location (line, column numbers and character offset), and tags or selected text are displayed in bottom status bar, meanwhile, marked tokens are shown in a central text edit widget.

Back-and-forth Bi-direction parsing

14                 River and stream flow one direction. Can XmlStreamReader reads back-and-forth in a bi-direction (bidi) manner? Yes. Here is an example why we need bidi parsing.

The following xml contains two placeholders in a paragraph. Using placeholder is to void the normal paragraph flow not being interrupted. Real contents are attached in a separate section next the paragraph.

15                 Our goal here is to restore the placeholder contents inplace:

16                 Question is when a reader reaches the placesholder how to fetch the real content ahead and insert them in current paragraph?

You may use two-parse solution: collect information and cache them in memory in the first parse, and restore them in the second parse. The disadvantages are parsing twice wastes time, and caching info costs memory. Is there a better solution fast and no memory cost? Yes.

To make the XmlStreamReader as a bidi parser, a derived class: XmlBidiReader provides methods:

class XmlBidiReader : public XmlStreamReader

{

public:

  XmlBidiReader();

  enum TokenType readNext();

 

  size_t tokenCount() const {return m_tokenCount;}

  bool backTo(size_t tokenCount);

 

  void lock();

  void unlock();

};

 

Here is a parsing flow.

A reader reads everything. When a placeholder is meet, do fetch:

fwstring XmlBidiTest::readText()

{

  fwstring id = rdr->attrs()[L"id"];

 

  fwstring displayText;

  fwstring talkText;

 

  while (!rdr->atEnd()) {

    rdr->readNext();

    if (rdr->isEndElement()) {

      if (rdr->name() == "t") break;

    }

    else if (rdr->isCharacters()) {

      displayText = rdr->text();

      talkText = fetch(id);

    }

  }

  return talkText;

}

 

fetch() has a locker at entrance. When fetch() is done, it repositions the reader back to the entrance, and continue on parsing rest of the paragraph.

fwstring XmlBidiTest::fetch(const fwstring & id)

{

  XmlBidiLocker locker(rdr); // return to current token

 

  bool inTalks = false; // inside talks section

  while (!rdr->atEnd()) {

    rdr->readNext();

    if (rdr->isStartElement()) {

      if (rdr->name() == "talks") {

        inTalks = true;

        continue;

      }

      if (inTalks) {

        if (rdr->name() == "t" && rdr->attrs()[L"id"] == id) {

          return readContent();

        }

      }

    }

  }

  return L""; // not found

}

 

Implementation details: a locker on XmlBidiReader:

class XmlBidiLocker

{

public:

  XmlBidiLocker(XmlBidiReader *rdr);

  virtual ~XmlBidiLocker();

private:

  XmlBidiReader *rdr;

};

 

The locker simply make a pair of two methods, lock() and unlock(), in its constructor and destructor.

XmlBidiLocker::XmlBidiLocker(XmlBidiReader *rdr)

: rdr(rdr)

{

  rdr->lock();   

}

XmlBidiLocker::~XmlBidiLocker()

{

  rdr->unlock();

}

 

"lock" means push a token into a stack,

void XmlBidiReader::lock()

{

  locks.push(m_tokenCount);

}

 

and "unlock" means pop a token out, and repositions the reader.

void XmlBidiReader::unlock()

{

  if (!locks.empty()) {

    this->backTo(locks.top());

    locks.pop();

  }

}

 

Repositioning looks up a map:

/// Back to a previously read token.

bool XmlBidiReader::backTo(size_t n)

{

  std::map <size_t, Position> ::const_iterator i = token2pos.find(n);

  if (i == token2pos.end()) return false; // not found

 

  m_tokenCount = n;

  m_ch = i->second.ch;

  if(m_atEnd) m_atEnd = false;

  return m_src->jumpTo(i->second.line, i->second.col, i->second.off);

}

 

and the map is built in one, and the only one, token consuming method: readNext()

enum TokenType XmlBidiReader::readNext()

{

  enum TokenType token = XmlStreamReader::readNext();

  if (token != INVALID_TOKEN) {

    ++ m_tokenCount;

    token2pos[m_tokenCount] = Position(lineNumber(), columnNumber(), characterOffset(), m_ch);

  }

  return token;

}

 


This solution is fast, because it parses once, not twice.
This solution is scalable, because there is no data caching, no any content put into memory for later use.

Application: Extract HTML text

/*!

  Parse and extract text. Has os (Output Stream) if there is writer.

*/

void HtmlTextReader::parse()

{

  while (!rdr->atEnd()) {

    rdr->readNext();

 

    if (rdr->isStartElement()) {

      if (rdr->name() == "script") {

        rdr->readRawTillEnd("script");

      }

      if (needLineBreak(rdr->name())) {

        if (os) *os << endl;

      }

    }

    else if (rdr->isCharacters()) {

      if (!rdr->isWhitespace()) {

        if (os) *os << sfm::trimmed(rdr->text());

      }

    }

  }

 

  if (rdr->hasError()) {

    if (os) *os << endl << rdr->errstring();

  }

}

 

Application: HTML validator:

Application: XML validator

XML tree

17                 If you ask a tree from a stream reader, you get a tree.

    if (rdr->isStartElement()) {

      if (rdr->name() == "rPr") {

        TokenNode *rPr = rdr->tree();

      }

    }

 

18                 more ...

( link )

class StreamCacher :public StreamReader

1                                             A cache reader, which remains the same flow as primary StreamReader, beyond, it caches internally.

2                                             One can specify which tag uses cache.

3                                             One can stop cache by setNoCache().

4                                             One can read cache the same way as a stream reader by taking a reference StreamCacher.

      StreamCacher r;

      StreamReader * reader = new StreamCacher(r);

 

5                                             One can reset to anywhere to start reading as a stream.

6                                             Possible to structuralized as a tree, for example,

       TokenNode * root = StreamCacher(r).tree(); 

 

Other XML parsers


Xerces/Xalan / VisualParser ? Use cannon, fire a missile, target a fly?
My stream parser is simple, light-weight, faster, and highly portable (implemented by C++ STL, Windows/Linux platform-independent), with big advantage of data pulling approach, which allows you to build recursive descent parsing patterns.

Related junk

o                  Extensible Stylesheet Language Transformations (XSLT)- It operates on XML sources to produce XSL-FO, other XML, or HTML.

o                  XLS-FO (Formatting Objects)- A presentation format usually generated by XSL transformations.

o                  XPath- A query language used by XSLT to access the different information items that compose XML documents

o                  International Organization for Standardization (ISO)- a non-governmental organization, acts as a consortium with strong links to governments.

o                  ISO Schematron- Schematron is a rule-based validation language for making assertions about the presence or absence of patterns in XML trees. It typically uses XPath to describe patterns.

19                

20                 References:

1                     XML 1.0 (5th edition, 26 November 2008)

2                     QXmlStreamReader

3                     Processing XML with Xerces and the DOM

4                     Processing XML with Xerces and SAX

21                

XmlStreamReader | Tree

 

 

 

 

1、立体几何长方体的继承关系

 

 

 

 

 

 

 

 

 

 

 

 

 

 


2、QComboBoxItem 加载QIcon

Example:

int cbWidth =ui.comboBox->width();

int cbHeigth =ui.comboBox->height();

QPixmappixmap(cbWidth, cbHeigth);

QPainterpainter(&pixmap);

painter.fillRect(0, 0, cbWidth,cbHeigth, Qt::white);

//一定要加Qt::white这样QComboBox中的Icon就不会显示默认的黑色

painter.drawLine(8,8,13,13);

painter.drawLine(13,8,8,13);

ui.comboBox->setIconSize(QSize(cbWidth, cbHeigth));

//QComboBox由两部分组成一部分是QIcon和QLabel组成,所以要设置QIconsize

ui.comboBox->addItem(QIcon(pixmap),QObject::tr(""),Qt::white);

3、修改的类名与图形对应记录

CDrawObject_FloatBlanket_Hua_Right花括号右

CDrawObject_FloatBlanket_Hua_Left花括号左

CDrawObject_FloatBlanket_Hua_LeftRight花括号左右

CDrawObject_FloatBlanket_Yuan_Right小括号右

CDrawObject_FloatBlanket_Yuan_Left小括号左

CDrawObject_FloatBlanket_Yuan_LeftRight小括号左右

4、常用快捷键

VS:上一个查询地点 Ctrl+-(不是负号) 下一个查询地点Ctrl+Shift+-

Eclipse:Alt+?调出函数指示

5、Excel锁定某一行的单元格方法

选取此单元格下一行并且进行选择窗口---冻结窗口来锁定这一行。

6、如何查找和修改某一个类

 

1、立体几何长方体的继承关系

 

 

 

 

 

 

 

 

 

 

 

 

 

 


7、QComboBoxItem 加载QIcon

Example:

int cbWidth =ui.comboBox->width();

int cbHeigth =ui.comboBox->height();

QPixmappixmap(cbWidth, cbHeigth);

QPainterpainter(&pixmap);

painter.fillRect(0, 0, cbWidth,cbHeigth, Qt::white);

//一定要加Qt::white这样QComboBox中的Icon就不会显示默认的黑色

painter.drawLine(8,8,13,13);

painter.drawLine(13,8,8,13);

ui.comboBox->setIconSize(QSize(cbWidth, cbHeigth));

//QComboBox由两部分组成一部分是QIcon和QLabel组成,所以要设置QIconsize

ui.comboBox->addItem(QIcon(pixmap),QObject::tr(""),Qt::white);

8、修改的类名与图形对应记录

CDrawObject_FloatBlanket_Hua_Right花括号右

CDrawObject_FloatBlanket_Hua_Left花括号左

CDrawObject_FloatBlanket_Hua_LeftRight花括号左右

CDrawObject_FloatBlanket_Yuan_Right小括号右

CDrawObject_FloatBlanket_Yuan_Left小括号左

CDrawObject_FloatBlanket_Yuan_LeftRight小括号左右

9、常用快捷键

VS:上一个查询地点 Ctrl+-(不是负号) 下一个查询地点Ctrl+Shift+-

Eclipse:Alt+?调出函数指示

10、Excel锁定某一行的单元格方法

选取此单元格下一行并且进行选择窗口---冻结窗口来锁定这一行。

11、如何查找和修改某一个类

 

在C语言中动态的一维数组是通过malloc动态分配空间来实现的,动态的二维数组也可以通过malloc动态分配空间来实现。

  实际上,C语言中没有二维数组,至少对二维数组没有直接的支持,取而代之的是“数组的数组”,二维数组可以看成是由指向数组的指针构成的数组。对于一个二维数组p[i][j],编译器通过公式*(*(p+i)+j)求出数组元素的值:

  1、p+i 计算行指针。

  2、*(P+i) 具体的行,是一个指针,指向该行首元素地址。

  3、*(P+i)+j 得到具体元素的地址。

  4、*(*(p+i)+j) 得到元素的值。

  基于上述原理,我们可以通过分配一个指针数组,再对指针数组的每一个元素分配空间实现动态分配二维数组。

  实现

  下面是本人写的一个动态分配二维数组的实现,适用于任何类型的二维数组,可以直接使用。

  类型定义和错误代码

typedef unsigned char MK_Byte;

#define SUCCESS 0 /*No error*/
#define MFAILED 1 /*General failure*/
#define MNOMEMORY 2 /*Out of memory*/

声明

//确保初始化
#define DeclareTwoDArray(ATYPE, iname) ATYPE ** iname = NULL

//定义自己的malloc和free,确保内存正确操作
#define MKMALLOC(nsize) malloc(nsize)
#define MKFREE(name) \
if (NULL != name)\
free(name);\
name = NULL

  实现

int MKCreatArray(int nsize, int X, int Y, void *** parray)
{
 void** tdarray = NULL;
 MK_Byte* tmparray = NULL;
 inti = 0;

 *parray= NULL;

 //分配指针数组
 if(!(tdarray = (void **)MKMALLOC(sizeof(MK_Byte *) * Y))) {
  returnMNOMEMORY;
 }
 //分配实际数组空间
 if(!(tmparray = (MK_Byte * )MKMALLOC(nsize * (X * Y)))) {
  MKFREE(tdarray);
  returnMNOMEMORY;
 }

 //初始化内存
 memset(tmparray,0x00, nsize * (X * Y));

 //指针数组赋值
 for(i = 0; i < Y; i++)
  tdarray[i]= (tmparray + (i * X) * nsize);

 *parray= tdarray;
 returnSUCCESS;
}

void MKFreeArray(void *** parray)
{
 if(*parray) {
  MKFREE((*parray)[0]);
  MKFREE((*parray));
 }
}

  使用

void testTwoDArray()
{
 //声明数组
 DeclareTwoDArray(int,a);
 DeclareTwoDArray(float,b);

 //创建整型数组
 MKCreatArray(sizeof(int),3, 2, &a);
 a[1][2]= 10;
 a[0][1]= 23;
 printf("%d,%d\n",a[1][2],a[0][1]);
 //使用完一定要FREE
 MKFreeArray(&a);

 //重新分配数组
 MKCreatArray(sizeof(int),6, 6, &a);
 a[5][5]= 234;
 a[4][0]= 567;
 printf("%d,%d\n",a[5][5],a[4][0]);
 MKFreeArray(&a);

 //创建浮点数组
 MKCreatArray(sizeof(float),2,2,&b);
 b[0][0]= 0.5f;
 b[1][1]= 0.006f;
 printf("%g,%g\n",b[0][0],b[1][1]);
 MKFreeArray(&b);

2、Java虚拟机是什么概念。

3、虚拟机如何虚拟操作系统。

 

 

 

 

 

Qt发布程序有两种方式,静态编译和动态编译。静态编译操作繁琐,东拉西扯要N长时间,所以我选择的是动态发布,动态发布有个缺点,就是要附加多个dll文件,传输极为不便,如果能搞成单文件就比较爽了。

本文就是讲述如何将多个文件打包成一个exe文件。

当然,你首先要将Qt编译设置成Release模式,将Release文件夹中的exe文件拷贝出来,并用微软的DependencyWalker查看该exe文件需要哪些dll(需要在完全没有装QT的系统上测试发布的程序有没有DLL依赖问题),并将其拷贝出来,将所有文件都放在同一个文件夹。搞定这些之后,就可以开始文件打包了。

文件夹打包需要几个软件,下面将一一讲述。

1、ASPACK

Qt本身所带的dll文件比较大,可以先用ASPACK压缩一下。mingwm10.dll,QtCore4.dll,libgcc_s_dw2-1.dll,QtGui4.dll等dll文件经过ASPACK压缩后可从十多M变为5M左右,大大降低了程序大小。

   

2、FilePacker

此软件可以从网上搜索下载。

  

 

按照提示,用这个软件一步步即可。可设置解包后运行文件,如图所示。

 

 

 

   然后点下一步,使用默认设置即可。

在设置临时解压路径的时候需要注意一下,最好是设置在临时文件夹,这样重启电脑后,这些解压的文件就自动删除了。如下图所示。

   

   

 

唯一美中不足的就是自定义图标必须是32*32大小,256色。当然,你可以找个ico图标编辑软件,编辑之后使之满足条件即可。

软件打包后就可以发布了。

还有个软件MoleBox也可以将文件夹打包,但是这个软件不能自定义图标,所以用起来就不爽了。

文件夹打包从根本上来讲应该就是压缩文件,这种压缩文件解压后能够自动运行压缩包中的文件,当然用WinRAR也能实现上述功能,只不过FilePacker操作更为简单,傻瓜式操作。打包后的exe文件,点右键时,很明显的看到能够用WinRAR操作。因此,文件很多的时候可能会打开较慢(文件多,解压时间长)。

以上提到的软件都是绿色软件。若您在网上没找到,请发邮件到xjtudll@foxmail.com来索取。

本文出自: 鸟的天空, 原文地址:http://www.xjtudll.cn/Exp/63/

 

 

 

Qt】如何打包发布基于Qt4Windows的软件

Qt2009-08-08 11:41:04阅读613评论0字号:大中小

(本文部分内容出自Qt文档Deploying anApplication on Windows)

先从Windows平台开始。Windows平台下的软件发布最主要的需求是想办法找到在你的发布中应该包含哪些必须的文件,同时要保证应用程序运行时能正确找到这些文件,发布基于Qt的软件也是同样的需求。就不同的情况一一阐述:

静态链接的情况

静态链接是最简单的情况,这种情况下需要发布的文件数量是最少的,只需要发布一个单独的执行档外加编译器相关的dll文件。这种情况下Qt库首先要静态编译:

<[other -static>

nmakesub-src

//如果用mingw编译,nmake替换成mingw32-make
//sub-src
指只编译src目录,这样省去编译examples等目录的时间

注意哦,如果你在同一个build目录用不同的configure选项去编译Qt,  必须在重新configure之前运行nmake distclean清除以前生成的目标和中间文件,保证一个干净的编译环境,不然有可能会出一些奇怪的链接错误哦~~

编译好Qt静态库下一步再编译应用程序:
cd application_dir
nmake clean
qmake -config release
nmake

编译成功之后应该得到一个可以独立执行的exe文件,可以将程序拷贝到其他没有安装qt的机器上测试。需要注意的是这个程序不一定百分之百可以运行,因为编译器带的库仍然是动态编译的,如果你的目标机里没有这些库的话仍然会有运行时的问题。后面会讲到如何用工具来检查应用程序的依赖。

静态链接方法比较重要的缺陷是无法支持插件而且插件不能编译进程序中,所以插件提供的功能就丢失了。这样一来要想用到插件的功能还是要用下面的方法。

动态链接的情况

动态链接程序的发布需要解决两个问题, Qt库需要与应用一起发布,另外插件也要一起打包,并保证放在适当的位置,这样应用程序才能找到它。
动态编译应用的基础是先将Qt库动态编译(默认参数即是动态编译),这样用普通的程序编译流程就可生成动态编译的执行档,使用的命令与上面相同。我们可以用一个Qt的例子测试前面说的发布方法,Qt包里带的例子Plug & Paint
是个非常合适的测试例子,它既包含应用又自带插件文件,可以很好的验证发布是否正确。该例子在examples/tools/plugandpaint下。这个例子如果编译成功,得到一个plugandpaint.exepnp_basictools.dllpnp_extrafilters.dll两个插件文件。

程序打包

第一步,将应用程序和Qt库拷贝到同一目录。(Windows下库的搜索先从当前目录开始,然后是在系统PATH环境变量指定的路径查找。)
第二步,检查应用程序还依赖哪些dll,如编译器带的dll或其他系统dll参见应用程序的依赖关系一节。
第三步,验证程序可以在目标系统上正确运行,将目前包里的文件拷贝到目标系统上,尝试运行程序。
第四步,发布插件程序。插件和普通的动态库的发布不同,不能简单的将之拷贝到应用目录里。应用程序在运行时会在其对应的plugins目录下去查找插件。针对这个例子,发布包应该类似这样的结构:

模块

文件名

执行档

plugandpaint.exe

Basic Tool插件

plugins\pnp_basictools.dll

ExtraFilters插件

plugins\pnp_extrafilters.dll

Qt Core模块

qtcore4.dll

Qt Gui模块

qtgui4.dll

除了程序和Qt库,还有下面的编译器库:

 

VC++ 6.0

VC++ 7.1 (2003)

VC++ 8.0 (2005)

C运行库

msvcrt.dll

msvcr71.dll

msvcr80.dll

C++运行库

msvcp60.dll

msvcp71.dll

msvcp80.dll

插件的位置除了Qt默认的路径还可以通过代码里调用QtAPI来指定,相应的APIQApplication::addLibraryPath()QApplication::addLibraryPaths().如:

qApp->addLibraryPath(”c:\some\path”);

上述代码的推荐调用位置是在main函数中,QApplication构造完毕之后。应用程序会在搜索默认路径之后去搜索你指定的库路径。

VisualStudio 2005

vs2005编译的程序在发布的时候还需要考虑一些额外的情况,比较麻烦点。要把manifest文件拷贝到应用程序的目录,这个文件包含应用的依赖信息,在运行时需要用到。另外,如果你的动态库的依赖和应用不同,那么还需要把manifest文件内嵌到dll文件中。Qt4.1.3之后的版本提供了CONFIG选项来提供内嵌manifest文件的功能,embed_manifest_dllembed_manifest_exe,用法是将下面的选项加入pro文件,如下:

CONFIG+=embed_manifest_exe

默认情况下embed_manifest_dll已经开启。关于manifest文件的更多信息参考MSDN的相关文章

有两种发布vc运行库的方法,一个是安装vs的运行库到目标系统中,另外是将库打包到应用程序的目录。打包vs运行库很简单,就是把<Visual Studio InstallPath>\VC\redist\<Architecture>\Microsoft.VC80.CRT拷贝到应用程序目录,与应用程序一起打包。如果你在打包运行库的同时还要发布插件程序,要注意把manifest文件从插件中去掉,不然在一些系统上会导致插件无法加载。去掉manifest的方法是在插件的pro文件中加入下面的选项:

CONFIG-=embed_manifest_dll

VS系统的运行包可以免费获得,只需要将这个安装包和你的应用安装包一起发布,并且在安装你的程序的时候去运行这个安装包就行了。比如32位的x86系统,安装32bit-x86-vs运行时包其他平台对应的包可以在微软网站找到。

应用程序的依赖关系

额外的依赖库

这里我们的秘密武器终于隆重登场了!那就是Dependency Walker工具。看一张截图:

用这个工具检查上面的例子,发现下面的库不是系统自带的:

Qt

VC++ 6.0

VC++ 7.1 (2003)

VC++ 8.0 (2005)

MinGW

QTCORE4.DLL

QTGUI4.DLL

MSVCRT.DLL

MSVCP60.DLL

MSVCR71.DLL

MSVCP71.DLL

MSVCR80.DLL

MSVCP80.DLL

MINGWM10.DLL(如果用mingw来编译的话需要这个库)

别忘了也检查一下plugin库的依赖。

Qt自带的插件

很多情况下,我们的程序还依赖Qt带的一些插件,比如图像格式的支持或数据库驱动支持等。这些插件需要放在plugins的特定子目录下,如图像格式插件在plugins\imageformat.Qt搜索插件的默认路径是QTDIR\plugins这个路径已经写入了Qt库中,但我们可以通过以下几种方法来override这个路径。

1.                 编辑qt.conf文件,推荐的方法(后面将写一篇关于qt.conf的帖子)

2.                 用前面提到的QApplication::addLibraryPath函数

3.                 使用第三方的工具修改QtCore库里写入的路径

 

 

 

 

 

 

 

 

 

 

Part V  (Daily Examination)  :

1 read a file which is named *.cpp,Search the specified String and replace it to another one.

 

 

 

Install and configure the local CVS environment on Ubuntu 11.04

Firstly, you should install CVS by application->Ubuntu SoftwareCenter, and, CVSD as the same way. During these time, you should type the CVSrepository path to the CVSD.

Install and configure the local SVN on Ubuntu 11.04

            Firstly, we shouldinstall the software by commands:

Sudo apt-get install subversion

Secondly, you can create a repository on the local file system. Command:

Svnadmin create ~/mHealthPad

Thirdly, import the content to the repository. Command:

Svn import –m “” ~/Health/mHealth12 file:///home/palin/mHealthPad

Svnserve –d –r ~/mHealthPad

 

原创粉丝点击