首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在等离子体中连接微件的信号

在等离子体中连接微件的信号
EN

Stack Overflow用户
提问于 2013-02-16 03:59:17
回答 1查看 189关注 0票数 0

我是Qt的新手,正在尝试将按钮的纤毛信号与函数连接起来,同时编写一个等离子。我正在尝试使用一个外部函数作为public的public类型对象,这样我就可以使用它来连接单击的信号?使用gtk可以像on_...._clicked一样简单地做到这一点,但是在qt中有没有一种简单的方法,我们可以不再需要使用插槽?

代码语言:javascript
复制
#include "plasma-tutorial1.h"
#include<string.h>
#include <stdlib.h>
#include <QGraphicsLinearLayout>
#include <QPainter>
#include <QFontMetrics>
#include <QSizeF>
#include <QTextEdit>
#include <plasma/svg.h>
#include <plasma/theme.h>
#include <plasma/widgets/lineedit.h>
#include <plasma/widgets/pushbutton.h>
#include <plasma/widgets/textedit.h> 
//PlasmaTutorial1 mainf;

themainfunction(int choice,Plasma::LineEdit *m_lineEdit,
Plasma::TextEdit *m_displaytext)
{
char buffer[100];
const char *inp=(const char *)malloc(sizeof(char)*100);
QString input;
input=m_lineEdit->text();
QByteArray byteArray = input.toUtf8();
inp = byteArray.constData();
char *expression;
expression=(char *)malloc(sizeof(char)*100);
strcpy(expression,"sudo apt-");

switch(choice)
{
case 1:{
        strcat(expression,"get install ");
        strcat(expression,inp);
        break;
      };
case 2:{
        strcat(expression,"get remove ");
        strcat(expression,inp);
        break;
      };
case 3:{
        strcat(expression,"cache search ");
        strcat(expression,inp);
        break;
      };
};
/*
FILE* in;
FILE* ptr=fopen("new.txt","w");
FILE *popen();
if(!(in = popen("cal","r")))
    {return;}

    while(fgets(buffer, 100, in) != NULL) {
*/
m_displaytext->append("yeah!");
//    fprintf(ptr,"%s",buffer);

            //}
//pclose(in);
//fclose(ptr);
}
PlasmaTutorial1::PlasmaTutorial1(QObject *parent, const QVariantList &args)
    : Plasma::Applet(parent, args),
    m_svg(this),
    m_icon("document")
{
    m_svg.setImagePath("widgets/background");
    // this will get us the standard applet background, for free!
    setBackgroundHints(DefaultBackground);
    resize(200, 200);
}


PlasmaTutorial1::~PlasmaTutorial1()
{
    if (hasFailedToLaunch()) {
        // Do some cleanup here
    } else {
        // Save settings
    }
}

void PlasmaTutorial1::init()
{

  /*  // A small demonstration of the setFailedToLaunch function
    if (m_icon.isNull()) {
        setFailedToLaunch(true, "No world to say hello");
    }*/
Counter rt;
    QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(this);
  layout->setOrientation(Qt::Vertical); //so widgets will be stacked up/down

  m_lineEdit = new Plasma::LineEdit(this);
  m_lineEdit->setText("Enter the package name here");

  m_displaytext = new Plasma::TextEdit(this);
  m_displaytext->setText("Terminal");

  m_installButton = new Plasma::PushButton(this);
  m_installButton->setText("Install");
  connect(m_installButton, SIGNAL(clicked()),&rt,SLOT(themainfunction(1,m_lineEdit,m_displaytext)));

  m_removeButton = new Plasma::PushButton(this);
  m_removeButton->setText("Remove");
  // m_removeButton->clicked()

  connect(m_removeButton, SIGNAL(clicked()),&rt,SLOT(themainfunction(2,m_lineEdit,m_displaytext)));

  m_searchButton = new Plasma::PushButton(this);
  m_searchButton->setText("Search");
  connect(m_searchButton, SIGNAL(clicked()),&rt,SLOT(themainfunction(3,m_lineEdit,m_displaytext)));


  layout->addItem(m_lineEdit);
  layout->addItem(m_installButton);
  layout->addItem(m_removeButton);
  layout->addItem(m_searchButton);
  layout->addItem(m_displaytext);   
  m_displaytext->append("yo baby!");    
} 

/* 
void PlasmaTutorial1::paintInterface(QPainter *p,
        const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
{
    p->setRenderHint(QPainter::SmoothPixmapTransform);
    p->setRenderHint(QPainter::Antialiasing);

    // Now we draw the applet, starting with our svg
    m_svg.resize((int)contentsRect.width(), (int)contentsRect.height());
    m_svg.paint(p, (int)contentsRect.left(), (int)contentsRect.top());

    // We place the icon and text
    p->drawPixmap(7, 0, m_icon.pixmap((int)contentsRect.width(),(int)contentsRect.width()-14));
    p->save();
    p->setPen(Qt::white);
    p->drawText(contentsRect,
                Qt::AlignBottom | Qt::AlignHCenter,
                "Hello Plasmoid!");
    p->restore();
}
 */
// This is the command that links your applet to the .desktop file
K_EXPORT_PLASMA_APPLET(tutorial1, PlasmaTutorial1)

#include "plasma-tutorial1.moc"

假设我想在单击install按钮的信号时连接want ()。我该怎么做呢?我如何在等离子体中派生一个类?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-17 13:37:29

我找到了我错过的地方。我们不能将对象作为参数传递给slot函数。现在它运行得很顺利。感谢您的回复。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14902419

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档