Qt_Class

来源:互联网 发布:淘宝商城注册流程 编辑:程序博客网 时间:2024/06/05 02:13

Common 

Words 


>MOC meta object compiler


Undertsanding

>qtmain Library

qtmain is a helper library that enables the developer to write a cross-platform main() function on Windows and on the Symbian platform.

If you do not use qmake or other build tools such as CMake, then you need to link against the qtmain library.

---Common End---


UI 

QDialog 

>adjustSize() adjust the size to its context if the context has set the size

>QCursor::pos() the mouse position

>QApplication::desktop() / QDesktopWidget::screenGeometry() / QDesktopWidget::availableGeometry()

>setAttribute(Qt::WA_DeleteOnClose, true) Dialog will be destroyed after close(), but NOT Null

>setWindowFlags((windowFlags() &~ Qt::WindowMinimizeButtonHint) | Qt::WindowContextHelpButtonHint | Qt::MSWindowsFixedSizeDialogHint);

&~ remove the flag, | add the flag, this is no Min button but with Help Button and size is fixed.

>raise() & activateWindow()

Raises this widget to the top of the parent widget's stack. 

Sets the top-level widget containing this widget to be the active window.

>showNormal() Restores the widget after it has been maximized or minimized

>setWindowFlags(Qt::Popup);

enum Qt::WindowType or flags Qt::WindowFlags

>setGemmetry() & move()

if visible, setGemmetry() will set the positon and size, receive the moveEvent() and/or resizeEvent()


TaskBar icon 

setParent of the main window, the icon will be the parent's, won't create new one.


QMenu 

>SubMenu

    QMenu mSystemTrayMenu;

    QMap<int, QAction*> mActionMap;

    QMenu* pDesktopSubMenu = mSystemTrayMenu.addMenu(tr("&Desktop"));

    mActionMap[1] = pDesktopSubMenu->menuAction();

    mActionMap[2] = CreateAction(tr("&BalloonA"), false, 2);

    pDesktopSubMenu->addAction(mActionMap.value(2));


QSystemTrayIcon 

>isSystemTrayAvailable()

---UI end---


Meta 

Q_INVOKABLE 

QMetaObject::invokeMethod().

 ---Meta End---


APP 

QApplication 

>setQuitOnLastWindowClosed()

default is true, App quits when the last visible primary window with the Qt::WA_QuitOnClose attribute set is closed.

QProcess 

>RunCommand

QString cmd = ("explorer.exe " + nativeFullDirPath);

QProcess::startDetached(cmd);

>Imp

QString exeFileWithQuotes = QString("\"%1\"").arg(exeFile);

QStringList args;

args.append("/restarting");

QProcess adSyncProcess;

adSyncProcess.startDetached(exeFileWithQuotes, args);

 

QScopedPointer
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon destruction.

 QScopedPointer<QApplication> app(createApplication(argc, argv));

 return app->exec();

 ---APP End---


Network 

QNetworkAccessManager 

replace the QHttp

>delete

Note: After the request has finished, it is the responsibility of the user to delete the QNetworkReply object at an appropriate time. Do not directly delete it inside the slot connected to finished(). You can use the deleteLater() function.

Note: Do not delete the reply object in the slot connected to this signal. Use deleteLater().

Destroys the QNetworkAccessManager object and frees up any resources. Note that QNetworkReply objects that are returned from this class have this object set as their parents, which means that they will be deleted along with it if you don't call QObject::setParent() on them.

>deleteLater for reply

Note: It is safe to call this function more than once; when the first deferred deletion event is delivered, any pending events for the object are removed from the event queue.

http://qt-project.org/forums/viewthread/14257 

--- Network End--- 


Other 

EventFilter 

QObject::installEventFilter

Example: monitoredObj->installEventFilter(filterObj);


QtScript 

    QFile qFile(":ToolTipStyle.qs");

    if (qFile.open(QIODevice::ReadOnly | QIODevice::Text))

    {

        QTextStream stream(&qFile);

        QString s = stream.readAll();

        qApp->setStyleSheet(s);

    }

    qFile.close();


QString 

>QString to const char *

toAscii()  fromAscii()

8-bit representation of the string as a QByteArray

toUtf8() fromUtf8()

UTF-8 is a Unicode codec and can represent all characters in a Unicode string like QString


QDataStream

>Output to file

QFile file1("F://file1.txt");

file1.open(QIODevice::WriteOnly);

QDataStream out1(&file1);   // we will serialize the data into the file

out1 << QString("TestApp_ShowMaterialEditor In ").toUtf8();  

---Other End---

原创粉丝点击